多并发下 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();
        }
    }

 

上一篇:CountDownLatch与CyclicBarrier与Semaphore的区别


下一篇:java并发工具