日期:2014-05-20 浏览次数:20762 次
package thread;
public class ThTest {
void fun1() {
fun2();
System.out.println("fun1");
}
void fun2() {
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 2; i++) {
System.out.println("fun2");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
public static void main(String[] args) {
ThTest th = new ThTest();
th.fun1();
}
}
void fun2() {
Thread t = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 2; i++) {
System.out.println("fun2");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
t.start();
try{
t.join();
}catch(Exception e){
e.printStackTrace();
}
}