线程的强制运行:join()方法
来源:互联网 发布:市场调查软件 编辑:程序博客网 时间:2024/06/06 07:35
/*线程的强制运行:join()方法*/
class MyThread4 implements Runnable{
public void run(){
for(int i=0; i<15; i++){
System.out.println(Thread.currentThread().getName()+"运行"+i);
}
}
}
public class ThreadJoin {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread4 mt = new MyThread4();
Thread th = new Thread(mt,"线程A");
th.start();
for(int i=0; i<25; i++){
if(i>7){
try {
th.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("xiancheng"+i);
}
}
}
/*
运行结果:
xiancheng0
xiancheng1
xiancheng2
xiancheng3
xiancheng4
xiancheng5
xiancheng6
xiancheng7
线程A运行0
线程A运行1
线程A运行2
线程A运行3
线程A运行4
线程A运行5
线程A运行6
线程A运行7
线程A运行8
线程A运行9
线程A运行10
线程A运行11
线程A运行12
线程A运行13
线程A运行14
xiancheng8
xiancheng9
xiancheng10
xiancheng11
xiancheng12
xiancheng13
xiancheng14
xiancheng15
xiancheng16
xiancheng17
xiancheng18
xiancheng19
xiancheng20
xiancheng21
xiancheng22
xiancheng23
xiancheng24
*/
class MyThread4 implements Runnable{
public void run(){
for(int i=0; i<15; i++){
System.out.println(Thread.currentThread().getName()+"运行"+i);
}
}
}
public class ThreadJoin {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread4 mt = new MyThread4();
Thread th = new Thread(mt,"线程A");
th.start();
for(int i=0; i<25; i++){
if(i>7){
try {
th.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("xiancheng"+i);
}
}
}
/*
运行结果:
xiancheng0
xiancheng1
xiancheng2
xiancheng3
xiancheng4
xiancheng5
xiancheng6
xiancheng7
线程A运行0
线程A运行1
线程A运行2
线程A运行3
线程A运行4
线程A运行5
线程A运行6
线程A运行7
线程A运行8
线程A运行9
线程A运行10
线程A运行11
线程A运行12
线程A运行13
线程A运行14
xiancheng8
xiancheng9
xiancheng10
xiancheng11
xiancheng12
xiancheng13
xiancheng14
xiancheng15
xiancheng16
xiancheng17
xiancheng18
xiancheng19
xiancheng20
xiancheng21
xiancheng22
xiancheng23
xiancheng24
*/
0 0
- 线程的强制运行:join()方法
- 后台线程与setDaemon()方法和线程的强制运行
- 线程的join方法
- 线程的join方法
- 线程的join方法
- 线程的join方法
- 线程的join()方法
- 线程join()方法join的含义
- Java线程的join方法
- Java线程的join方法
- 线程的join方法练习
- Java线程的join()方法
- 线程的休眠和强制运行
- 线程的停止、守护线程、join()方法
- 3.2.2用join方法使线程排队运行
- Java 多线程(四)强制运行Join
- Java的线程的join()方法
- 用户线程、守护线程、线程的join()方法
- Android Video
- TOPOGRAPHIC LASER RANGING AND SCANNING Principles and Processing学习笔记
- iOS开发-URLSession使用-URLSession网络请求
- C++编程笔记
- 线性表之顺序表增强操作
- 线程的强制运行:join()方法
- 第六周书面项目(1):程序理解
- MyBatis官方教程及源码解析——mapper映射文件
- java核心基础文章精选
- HttpClient使用SESSIONID模拟用户发送请求
- hdu 3339 In Action 最短路spfa+背包
- swift学习之路之UITabBrarController的简单使用
- result的属性
- Java 读取 AD 用户