日期:2014-05-20 浏览次数:20818 次
public class MachineSuspendResume extends Thread {
private int a;
public void run() {
for(int i=0;i<1000;i++){
synchronized(this){
a+=i;
yield();
a-=i;
}
}
}
public synchronized void reset() {
a=0;
}
public static void main(String[] args) throws InterruptedException {
MachineSuspendResume machine = new MachineSuspendResume();
machine.start();
yield();
machine.suspend();
machine.reset();
machine.resume();
}
}