(String[] args)
| 51 | |
| 52 | public class DelayQueueDemo { |
| 53 | public static void |
| 54 | main(String[] args) throws Exception { |
| 55 | DelayQueue<DelayedTask> tasks = |
| 56 | Stream.concat( // Random delays: |
| 57 | new Random(47).ints(20, 0, 4000) |
| 58 | .mapToObj(DelayedTask::new), |
| 59 | // Add the summarizing task: |
| 60 | Stream.of(new DelayedTask.EndTask(4000))) |
| 61 | .collect(Collectors |
| 62 | .toCollection(DelayQueue::new)); |
| 63 | while(tasks.size() > 0) |
| 64 | tasks.take().run(); |
| 65 | } |
| 66 | } |
| 67 | /* Output: |
| 68 | [128] Task 12 [429] Task 6 [555] Task 2 [551] Task 13 |