所有示例均在gihub(ssh_base)中====>https://github.com/chengyangyang

多并发下 SimpleDateFormat 出现错误

 

  

 private static String time = "2019-01-11 11:11:11";
    private static long timestamp = 1547176271000L;
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        dateFormatTest(x->{
            try {
                Date date = dateFormat.parse(time);
                if (date.getTime() != timestamp){
                    System.out.println("转化错误:"+date);
                }
            } catch (Exception e) {
                System.out.println("出现异常"+e.getMessage());
            }
        });
    }
    private static void dateFormatTest(Consumer runnable){
        CountDownLatch countDownLatch = new CountDownLatch(1000);
        for (int i = 0; i < 1000; i++) {
            new Thread(()->{
                runnable.accept(null);
                countDownLatch.countDown();
            }).start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

 

posted @ 2019-06-25 18:48  ☞书香门第☜  阅读(275)  评论(0编辑  收藏  举报
http://count.knowsky.com/count1/count.asp?id=434520&sx=1&ys=64"