(String[] args)
| 10 | public class QuittingTasks { |
| 11 | public static final int COUNT = 150; |
| 12 | public static void main(String[] args) { |
| 13 | ExecutorService es = |
| 14 | Executors.newCachedThreadPool(); |
| 15 | List<QuittableTask> tasks = |
| 16 | IntStream.range(1, COUNT) |
| 17 | .mapToObj(QuittableTask::new) |
| 18 | .peek(qt -> es.execute(qt)) |
| 19 | .collect(Collectors.toList()); |
| 20 | new Nap(1); |
| 21 | tasks.forEach(QuittableTask::quit); |
| 22 | es.shutdown(); |
| 23 | } |
| 24 | } |
| 25 | /* Output: |
| 26 | 11 23 20 12 24 16 19 15 35 147 32 27 7 4 28 31 8 83 3 1 |