···
package niub;
public class piaozi {
public static int count = 50 ;
}
···
···
package niub;
public class piaozi01 {
public static void main(String[] args) {
Runnable mythread = new Runnable() {
@Override
public void run() {
synchronized (this){
System.out.println(Thread.currentThread().getName()
+ "卖出了一张票,还剩:" + (--piaozi.count) + "张"
);
}
}
};
new Thread(mythread, "线路1").start();
new Thread(mythread, "线路2").start();
new Thread(mythread, "线路3").start();
new Thread(mythread, "线路4").start();
new Thread(mythread, "线路5").start();
}
···