zoukankan      html  css  js  c++  java
  • 【疑难杂症】new Date() 造成的线程阻塞问题

    代码如下

    package com.learn.concurrent.probolem;
    
    import java.util.Date;
    import java.util.concurrent.CountDownLatch;
    
    /**
     * @author wx
     * @Description
     * @date 2019/05/12 18:33
     */
    public class DateProblem {
        public static void main(String[] args) {
            new DateProblem().execute();
        }
    
        public void execute() {
            CountDownLatch latch = new CountDownLatch(1);
            new Thread(new Worker(latch)).start();
            try {
                latch.await(); 
                System.out.println("work has been done");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    
        class Worker implements Runnable {
    
            private CountDownLatch latch;
    
            public Worker(CountDownLatch latch) {
                this.latch = latch;
            }
    
            @Override
            public void run() {
                System.out.println("point 1");
                System.out.println("point 2"+new Date());
                latch.countDown();
            }
        }
    }

    在上面红色代码出设置一个断点,发现只有"Point 1"这条消息输出了,"Point 2" 这条消息没有输出

  • 相关阅读:
    leetcode643.滑动窗口例题
    BZOJ4195 离散化+并查集
    luogu线性表刷题
    2021-5-29 周报博客
    2021-5-28 日报博客
    2021-5-27 日报博客
    2021-5-26 日报博客
    2021-5-25 日报博客
    2021-5-24 日报博客
    梦断代码阅读笔记之二
  • 原文地址:https://www.cnblogs.com/heben/p/10853677.html
Copyright © 2011-2022 走看看