public class CachedThreadPoolExample { public static void main(String[] args) { ExecutorService exec = Executors.newCachedThreadPool(); for (int i = 0; i <5; i++) { exec.execute(new Task()); } exec.shutdown(); } } ```
public class FixedThreadPoolExample { public static void main(String[] args) { ExecutorService exec = Executors.newFixedThreadPool(5); for (int i = 0; i <5; i++) { exec.execute(new Task()); } exec.shutdown(); } } ```
public class SingleThreadExecutorExample { public static void main(String[] args) { ExecutorService exec = Executors.newSingleThreadExecutor(); for (int i = 0; i <5; i++) { exec.execute(new Task()); } exec.shutdown(); } } ```