package com.qyl.maipiao.one2;
public class eldrly implements Runnable{
int count = 50;
@Override
public void run() {
while (count>0) {
synchronized(eldrly.class){
if (count>0) {
System.out.println(Thread.currentThread().getName()+"正在销售第"+count+"张票");
count--;
}
}
}
}
}
package com.qyl.maipiao.one2;
public class count {
public static void main(String[] args) {
eldrly eld = new eldrly();
new Thread(eld,"老人").start();
new Thread(eld,"小孩").start();
new Thread(eld,"军人").start();
}
}