?? machine.java
字號(hào):
package correctstart;
public class Machine extends Thread{
private int a=0;
private static int count=0; //統(tǒng)計(jì)被啟動(dòng)的Machine線(xiàn)程的數(shù)目
public void start(){
super.start();
System.out.println(currentThread().getName()
+":第"+(++count)+"個(gè)Machine線(xiàn)程啟動(dòng)"); //這行代碼由主線(xiàn)程執(zhí)行
}
public void run(){
for(a=0;a<50;a++){ //使用Machine對(duì)象的實(shí)例變量a
System.out.println(currentThread().getName()+":"+a);
try{
sleep(100);
}catch(InterruptedException e){ throw new RuntimeException(e);}
}
}
public static void main(String args[]){
Machine machine1=new Machine();
Machine machine2=new Machine();
machine1.start();
machine2.start();
}
}
/****************************************************
* 作者:孫衛(wèi)琴 *
* 來(lái)源:<<Java面向?qū)ο缶幊?gt;> *
* 技術(shù)支持網(wǎng)址:www.javathinker.org *
***************************************************/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -