public static void main(String[] args) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
long start = System.currentTimeMillis();
System.out.println("I'am start--->" + start);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("I'am dead");
Thread.sleep(50000000);
} catch (Exception e) {
e.printStackTrace();
} finally {
}
latch.countDown();
}
});
t.start();
latch.await(10, TimeUnit.SECONDS); //等待10秒后,如果线程没有执行完,则不再等待,进入后续
System.out.println("Game Over");
t.interrupt();
// t.stop();
long end = System.currentTimeMillis();
System.out.println("I'am end--->" + end);
System.out.println(end - start);
}
网友评论