import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Demo { public static void main(String[] args) { ExecutorService es= Executors.newFixedThreadPool(4); Runnable runnable=new Runnable() { private int ticket=100; @Override public void run() { while(true){ if(ticket<=0){ break; } System.out.println(Thread.currentThread().getName()+"卖了第"+ticket+"张票"); ticket--; } } }; for(int i=0;i<4;i++){ es.submit(runnable); } es.shutdown(); } }
全部评论
(0) 回帖