04
Jan
Let's say you want to execute some tasks. Since executing it through a single thread might take you quite some time to get the result, you decide to use the ever dependable ExecutorService to process it through multiple threads. Here's a sample: public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; i++) { int temp = i; executorService.submit(() -> { task(temp); }); } executorService.shutdown(); System.out.println("ExecutorService is shutdown"); } private static void task(int temp) { try { TimeUnit.SECONDS.sleep(1L); System.out.println("Task " + temp + " completed"); } catch (InterruptedException e) { throw new…