Example #1
0
 public static void main(String[] args) {
   Random rand = new Random(47);
   ExecutorService exec = Executors.newCachedThreadPool();
   DelayQueue<DelayedTask> queue = new DelayQueue<DelayedTask>();
   // Fill with tasks that have random delays:
   for (int i = 0; i < 20; i++) queue.put(new DelayedTask(rand.nextInt(5000)));
   // Set the stopping point
   queue.add(new DelayedTask.EndSentinel(5000, exec));
   exec.execute(new DelayedTaskConsumer(queue));
 }
Example #2
0
 public void run() {
   for (DelayedTask pt : sequence) {
     printnb(pt.summary() + " ");
   }
   print();
   print(this + " Calling shutdownNow()");
   exec.shutdownNow();
 }