What is thread pool in java with example?
Answer / Shivam Agarwal
A thread pool in Java is a collection of threads that are reused to handle multiple tasks efficiently. An ExecutorService, such as Executors.newFixedThreadPool(int n), creates a thread pool with a fixed number of threads. Here's an example:
```
ExecutorService executor = Executors.newFixedThreadPool(5);
for (int i = 0; i < 10; i++) {
final int taskId = i;
Runnable worker = new Runnable() {
public void run() {
System.out.println("Task " + taskId);
}
};
executor.execute(worker);
}
executor.shutdown();
```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the use of static import ?
What is an i/o filter?
Any one can explain how the inerface uses in java. give with example.
What are the Class Libraries ?
What is a java applet? What is an interface?
Will the compiler creates a default constructor if I have a parameterized constructor in the class?
Is string serializable in java?
Convert a binary search tree to a sorted doubly linked list inplace.
What happens if an exception is not caught?
Write a program to check string is palindrome without using loop?
What is polymorphism in java? What are the kinds of polymorphism?
Are there any tools available in java to create reports?