package wo;
public class Ex extends Thread{
public Ex(String name)
{
super(name);
}
public void run()
{
for(int i=0;i<20;i++)
{
System.out.println("Myname is:"+getName()+(i+1));
try{
this.sleep(1000);
}catch(InterruptedException e){
System.out.println("線程被中斷!");
}
}
}
/**
* @param args
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
Ex ts=new Ex("Frist Thread");
Ex tr=new Ex("Second Thread");
ts.setPriority(Thread.NORM_PRIORITY+2);
tr.setPriority(Thread.NORM_PRIORITY-2);
ts.start();
tr.start();
ts.join();
tr.join();
System.out.println("主線程結束!");
}
}
Java線程(二)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.