Skip to content

Instantly share code, notes, and snippets.

@sne007
Last active September 24, 2020 05:39
Show Gist options
  • Save sne007/8a3de878ca0f0ece4208327927feaf4d to your computer and use it in GitHub Desktop.
Save sne007/8a3de878ca0f0ece4208327927feaf4d to your computer and use it in GitHub Desktop.
class Tasks {
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(3);
executorService.submit(new Task1());
executorService.submit(new Task2());
executorService.submit(new Task3());
executorService.shutdown();
}
}
/*
Output:
T1 is running on thread pool-1-thread-1
Computed prime number 17
T2 is running on thread pool-1-thread-2
Computed prime number 23
T3 is running on thread pool-1-thread-3
Computed prime number 13
Successfully put 23 in the database
Successfully put 17 in the database
Successfully put 13 in the database
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment