machinerush.java
来自「这一些程序都是实验之用」· Java 代码 · 共 30 行
JAVA
30 行
package synctatic;
public class MachineRush implements Runnable{
private static int a=1;
public void go(){ //this process is a
for(int i=0;i<1000;i++)
{
System.out.println(Thread.currentThread().getName()+":"+i);
Thread.yield();
}
}
public void run(){
for(int i=0;i<10;i++){
synchronized(this){ a+=i;
try{Thread.sleep(50);
}catch(InterruptedException e){throw new RuntimeException(e);}
}
}
}
public static void main(String args[])throws InterruptedException{
MachineRush machine=new MachineRush();
Thread t1=new Thread(machine);
Thread t2=new Thread(machine);
t1.start();
t2.start();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?