public class Demo10_Join {
/**
* @param args
*/
public static void main(String[] args) {
Thread t1 = new Thread() {
public void run() {
for(int x = 0; x < 10; x++) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("aaaaaaaaaaaaaaaa");
}
}
};
Thread t2 = new Thread() {
public void run() {
for(int x = 0; x < 10; x++) {
try {
if(x == 2)
//t1.join(); //让当前线程暂停,指定的线程执行,执行完后再让当前线程执行
t1.join(30);
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("bb");
}
}
};
t1.start();
t2.start();
}
}
|
|