package com.test.base.thread;
import junit.framework.Assert;
import org.junit.Test;
public class TestThread {
@Test
public void testJoinMethod(){
Thread t1 = new Thread(new R1(100));
Thread t2 = new Thread(new R1(1000));
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Complete");
while(true){
;
}
}
class R1 implements Runnable{
int max_num = 100;
public R1(int maxNum){
max_num = maxNum;
}
public void run() {
for(int i=0; i< max_num; i++){
System.out.print((Thread.currentThread().getId()%2 == 1)? "$$" : "**" );
System.out.println("[ Id = " + Thread.currentThread().getId() + " = " + i + "]") ;
}
}
}
}
线程等待join
最新推荐文章于 2024-10-14 10:06:19 发布