疑难杂症new Date() 造成的线程阻塞问题
Posted heben
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了疑难杂症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" 这条消息没有输出
以上是关于疑难杂症new Date() 造成的线程阻塞问题的主要内容,如果未能解决你的问题,请参考以下文章