try {
Thread.sleep(700);
} catch ( InterruptedException x ) {
// ignore
}
tt.loop();
}
}
join用来强制运行某一线程,下面的这个程序在I=100时会强制运行该线程
程序清单:JoinThread.java
public class JoinThread
{
public static void main(String[] args)
{
ThreadTest t=new ThreadTest();
Thread pp=new Thread(t);
pp.start();
int i=0;
while(true)
{
if(i==100)
{
try
{
pp.join(); //强制一线程运行完后,在运行后面的线程
}
catch(Exception e) //会抛出InterruptedException
{
System.out.println(e.getMessage());
}
}
System.out.println("main Thread "+i++);
}
共21页 第1页 第2页 第3页 第4页 第5页 第6页 第7页 第8页 第9页 第10页 第11页 第12页 第13页 第14页 第15页 第16页 第17页 第18页 第19页 第20页 第21页






