package 多线程练习;
public class Present extends Thread {
int number=100;
Object obj= new Object();
public void run(){
while(true){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (obj) {
if(number>=10){
System.out.println(Thread.currentThread().getName()+"***************发到第"+number+"份礼物");
number--;
}
}
}
}
}
|
|