多线程07.thread-join
package com.wangwenjun.concurrency.chapter5; public class ThreadJoin3 { public static void main(String[] args) throws InterruptedException { long startTimestamp = System.currentTimeMillis(); Thread t1 = new Thread(new CaptureRunnable("M1", 10000L)); Thread t2 = new Thread(new CaptureRunnable("M2", 30000L)); Thread t3 = new Thread(new CaptureRunnable("M3", 15000L)); t1.start(); t2.start(); t3.start(); t1.join(); t2.join(); t3.join(); //join可以将上面三个线程并行执行,但不执行下面的线程,等待上面线程执行后再执行下面的输出 long endTimestamp = System.currentTimeMillis(); System.out.printf("Save data begin timestamp is:%s, end timestamp is:%s\n", startTimestamp, endTimestamp); } } class CaptureRunnable implements Runnable { private String machineName; private long spendTime; public CaptureRunnable(String machineName, long spendTime) { this.machineName = machineName; this.spendTime = spendTime; } @Override public void run() { //do the really capture data. try { Thread.sleep(spendTime); System.out.printf(machineName + " completed data capture at timestamp [%s] and successfully.\n", System.currentTimeMillis()); } catch (InterruptedException e) { e.printStackTrace(); } } public String getResult() { return machineName + " finish."; } }
---------------------------------------------------------------------------
国之殇,未敢忘!
南京大屠杀!
731部队!
以及核污染水排海等一系列全无人性的操作,购买他们的食品和为它们提供帮助只会更加变本加厉的害你,呼吁大家不要购买日本相关产品
昭昭前事,惕惕后人
吾辈当自强,方使国不受他人之侮!
---------------------------------------------------------------------------
作者:三号小玩家
出处:https://www.cnblogs.com/q1359720840/
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 版权信息