コード例 #1
0
 public static void main(String[] args) throws Exception {
   Car car = new Car();
   ExecutorService exec = Executors.newCachedThreadPool();
   exec.execute(new WaxOff(car));
   exec.execute(new WaxOn(car));
   TimeUnit.SECONDS.sleep(5); // Run for a while...
   exec.shutdownNow(); // Interrupt all tasks
 }
コード例 #2
0
 public static void main(String[] args) throws Exception {
   ToastQueue dryQueue = new ToastQueue(),
       butteredQueue = new ToastQueue(),
       finishedQueue = new ToastQueue();
   ExecutorService exec = Executors.newCachedThreadPool();
   exec.execute(new Toaster(dryQueue));
   exec.execute(new Butterer(dryQueue, butteredQueue));
   exec.execute(new Jammer(butteredQueue, finishedQueue));
   exec.execute(new Eater(finishedQueue));
   TimeUnit.SECONDS.sleep(5);
   exec.shutdownNow();
 }
コード例 #3
0
 public static void main(String[] args) {
   ExecutorService exec = Executors.newCachedThreadPool();
   DelayQueue<Event> queue = new DelayQueue<Event>();
   GreenhouseControls gc = new GreenhouseControls(queue);
   gc.addEvent(gc.new Bell(900));
   Event[] eventList = {
     gc.new ThermostatNight(0),
     gc.new LightOn(200),
     gc.new LightOff(400),
     gc.new WaterOn(600),
     gc.new WaterOff(800),
     gc.new ThermostatDay(1400)
   };
   gc.addEvent(gc.new Restart(2000, eventList));
   if (args.length == 1) gc.addEvent(new GreenhouseControls.Terminate(new Integer(args[0]), exec));
   exec.execute(gc);
 }
コード例 #4
0
 public static void main(String[] args) throws Exception {
   ExecutorService exec = Executors.newCachedThreadPool(new DaemonThreadFactory());
   for (int i = 0; i < 10; i++) exec.execute(new DaemonFromFactory());
   print("All daemons started");
   TimeUnit.MILLISECONDS.sleep(500); // Run for a while
 }