zoukankan      html  css  js  c++  java
  • 多并发下 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();
            }
        }
  • 相关阅读:
    030-B+树(三)
    028-B+树(一)
    027-B树(二)
    026-B树(一)
    025-红黑树(六)
    024-红黑树(五)
    023-红黑树(四)
    022-红黑树(三)
    021-红黑树(二)
    020-红黑树(一)
  • 原文地址:https://www.cnblogs.com/chengyangyang/p/11084713.html
Copyright © 2011-2022 走看看