package com.pb.thread.demo; public class JoinTest extends Thread {
//带字符串name参数的构造方法
public JoinTest(String name){
super(name);
}
//重写run方法
public void run(){
//线程执行代码
for(int i=0;i<5;i++){
System.out.println(getName());
}
}
public static void main(String[]args){
for(int i=0;i<10;i++){
if(i==5){
//实例化JoinTest线程对象
Thread jt=new JoinTest("半路杀出线程"+i);
try{
jt.start();
jt.join();
}catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()+i);
}
} }
//带字符串name参数的构造方法
public JoinTest(String name){
super(name);
}
//重写run方法
public void run(){
//线程执行代码
for(int i=0;i<5;i++){
System.out.println(getName());
}
}
public static void main(String[]args){
for(int i=0;i<10;i++){
if(i==5){
//实例化JoinTest线程对象
Thread jt=new JoinTest("半路杀出线程"+i);
try{
jt.start();
jt.join();
}catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getName()+i);
}
} }