package org.nix.learn.thread;
/**
* @author zhangpei
* @version 1.0
* @date 2018/12/18
*/
public class Join {
private Object object;
public static void main(String[] args) throws InterruptedException {
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 50; i++) {
System.out.print("张沛" + " ");
}
}
});
thread1.start();
thread1.join();
JoinThread target = new JoinThread(thread1, "bisha",true);
new Thread(target).start();
}
static class JoinThread implements Runnable{
private Thread runnable;
private String print;
private Boolean red;
public JoinThread(Thread runnable, String print,Boolean red) {
this.runnable = runnable;
this.print = print;
this.red = red;
}
@Override
public void run() {
for (int i = 0; i < 50; i++) {
if (red){
System.err.print(print+" ");
}else {
System.out.print(print+" ");
}
}
}
}
}
执行结果:
请多尝试几次就能出线这几种情况