import java.util.concurrent.Executor;
public class test {
public static void main(String[] args) throws InterruptedException {
SubExecutor subExecutor=new SubExecutor();
subExecutor.execute(new TicketStation(200));
subExecutor.execute(new TicketStation(200));
}
static class TicketStation implements Runnable{
static int TicketsCount=0;
static int sellout=0;
public TicketStation(int count){
TicketsCount=count;
}
@Override
public void run(){
while (TicketsCount>sellout) {
try {
sellout++;
System.out.println("ticket sell out:"+sellout);
Thread.sleep(50);
} catch (InterruptedException ex) {
}
}
}
}
static class SubExecutor implements Executor{
@Override
public void execute(Runnable r)
{
new Thread(r).start();
}
}
}
执行结果:
标签:java,sellout,int,Executor,线程,TicketStation,new,static,public From: https://blog.csdn.net/geniusChinaHN/article/details/145133412