?? xiancheng.java
字號:
package zhaofei;
public class xiancheng{
public static void main(String[] args) {
int n = 0;
SimpleThread zf1 = new SimpleThread("1");
SimpleThread zf2 = new SimpleThread("2");
zf1.setPriority(1);
zf2.setPriority(5);
//for (int i=0 ;i<5; i++){
zf1.start(); //通過休眠 分別的執行 線程1 和2
zf2.start();
//}
//n = zf1.n;
//n = zf2.n;
//while (zf1.i <1) {
// n++;//System.out.println(zf1.i);
//}
System.out.println(n);
}
}
class SimpleThread extends Thread{
int i,n=0;
public SimpleThread(String str){
super(str);
}
public synchronized void run(){ //就在這里處理問題
for (this.i=0; i<8;i++){
System.out.println("<<" +i+" 線程" +getName()+">>");
try{
sleep((long)(Math.random()*50)); //sleep 指定進程執行多久休眠
// sleep(100);
}
catch (InterruptedException e){}
}
n=Integer.parseInt(getName());
System.out.println(getName()+ "完成" + this.n);
//n++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -