?? app14_6.java
字號:
// app14_6, 啟動線程的范例
class Ctest extends Thread // 從Thread類擴展出子類
{
private String id;
public Ctest(String str){ // 構(gòu)造函數(shù),設(shè)置成員id
id=str;
}
public void run(){ // 覆蓋Thread類里的run() method
for(int i=0;i<4;i++){
try{
sleep((int)(1000*Math.random()));
}
catch(InterruptedException e){}
System.out.println(id+" is running..");
}
}
}
public class app14_6
{
public static void main(String args[])
{
Ctest dog=new Ctest("doggy");
Ctest cat=new Ctest("kitty");
dog.start(); // 啟動dog線程
try{
dog.join(); // 限制dog線程結(jié)束后才能往下執(zhí)行
}
catch(InterruptedException e){}
cat.start(); // 啟動cat線程
try{
cat.join(); // 限制cat線程結(jié)束后才能往下執(zhí)行
}
catch(InterruptedException e){}
System.out.println("main() method finished");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -