import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolExample {
public static void main(String[] args) {
// Create a fixed pool of 3 threads
ExecutorService executor = Executors.newFixedThreadPool(3);
for (int i = 0; i < 5; i++) {
int taskNumber = i;
executor.execute(() -> {
System.out.println("Executing Task " + taskNumber + " inside " + Thread.currentThread().getName());
});
}
executor.shutdown();
}
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolExample {
public static void main(String[] args) {
// Create a fixed pool of 3 threads
ExecutorService executor = Executors.newFixedThreadPool(3);
}