程序代码:
package homework10.homework1014;
/**
* 回顾:
* 线程:
* 获取CPU时间片以进行线程的执行
* 知识点:
* join():让线程进入等待状态,等到其他线程执行完毕之后,该线程再执行
* @author Administrator
*
*/
public class Demo {
public static void main(String[] args) {
Thread down = new Thread(()->{
System.out.println("开始下载图片!");
for(int i=0;i<=100;i++){
try {
Thread.sleep(50);
System.out.println("图片下载进度:"+i+"%");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("下载完毕!!!");
});
Thread show = new Thread(()->{
System.out.println("开始显示图片!");
try {
down.join();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
for(int i=0;i<=100;i++){
try {
Thread.sleep(50);
System.out.println("图片显示进度:"+i+"%");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("图片显示完毕!!!");
});
down.start();
show.start();
}
}
代码运行效果视频:
java线程当中的join()方法的示例