?? forsome.java
字號:
package occupycpu;
public class ForSome extends Thread{
private static StringBuffer log =new StringBuffer();
private static int count =0;
public void run(){
/* for(int i=0;i<20;i++)
{
log.append(currentThread().getName()+":"+i+" ");
if(++count%10==0)log.append("\n");
}*/
/*for(int i=0;i<20;i++)
{
log.append(currentThread().getName()+":"+i+" ");
if(++count%10==0)log.append("\n");
try{
sleep(100);
}catch(InterruptedException e){throw new RuntimeException(e);}
}
}*/
/*try{
sleep(60000);
System.out.println("sleep end");
}catch(InterruptedException e){System.out.println("sleep interrupted");}
System.out.println("end");
}*/
for(int a=0;a<20;a++)
{
log.append(currentThread().getName()+":"+a+" ");
if(++count%10==0)log.append("\n");
yield();
}
}
public static void main(String arg[])throws Exception{
ForSome forsome1=new ForSome();
ForSome forsome2=new ForSome();
forsome1.setName("r1");
forsome2.setName("r2");
forsome1.start();
forsome2.start();
while(forsome1.isAlive()||forsome2.isAlive())
{Thread.sleep(1000);}
System.out.println(log);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -