JavaIntermediate#concurrency

What are the different thread pool types provided by Executors?

newFixedThreadPool creates a pool with a fixed number of threads; newCachedThreadPool creates threads as needed and reuses idle ones; newSingleThreadExecutor uses one worker thread; newScheduledThreadPool supports delayed/periodic tasks.

Example
ExecutorService fixed = Executors.newFixedThreadPool(5);
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> System.out.println("tick"), 0, 1, TimeUnit.SECONDS);

Related Questions

1
JavaAdvanced#concurrency

What is thread starvation?

Open
2
JavaIntermediate#java8#streams

What is the difference between map() and flatMap() in streams?

Open
3
JavaBeginner#streams

What is the difference between Collectors.toList() and Collectors.toSet()?

Open