黑马程序员技术交流社区
标题:
自己写的小小的thread的代码,希望能帮助大家
[打印本页]
作者:
wome789
时间:
2015-10-25 13:27
标题:
自己写的小小的thread的代码,希望能帮助大家
写的是join的使用。
package Thread;
public class TestJoin {
public static void main(String[] args) {
MyThread2 t1 = new MyThread2("T1");
t1.start();
try{
t1.join();
}
catch(InterruptedException e){}
for(int i=1;i<=10;i++) {
System.out.println("i am main thread");
}
}
}
class MyThread2 extends Thread {
MyThread2(String s) {
super(s);
}
public void run() {
for(int i=1;i<=10;i++) {
System.out.println("i am "+getName());
try {
sleep(1000);
}
catch(InterruptedException e) {
return;
}
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2