How would you implement a thread pool?



How would you implement a thread pool?..

Answer / Zakir Abbas Baaqri

In Java, a thread pool can be implemented using ExecutorService or Executors utility class. The Executors class provides factory methods that return an ExecutorService object.n
Here is a simple example of creating a fixed thread pool:n
```n
ExecutorService executor = Executors.newFixedThreadPool(5);n
```n
This creates a thread pool with a capacity of 5 threads.n
You can submit tasks to the thread pool using the `execute()` method:n
```n
Runnable task = new Runnable() {n @Overriden public void run() {n // Your code heren }n};n
executor.execute(task);n ```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Windows Threads Interview Questions

Hi, I'm now using windows 7 in my desktop. I have used a lot of audio recording and editing software but most of then doesn't support the compatibility of win7 and often disturbs. So can anyone tell me which one would be the best audio recording and editing software for win7? Thanks Emanali

1 Answers  


What are the benefits of multithreaded programming?

1 Answers  


difference between ntfs4 and ntfs5

3 Answers  


What's the difference in using runnable and extends in threads?

1 Answers  


Explain how to kill a particular process in windows?

1 Answers  


Explain yielding in threading?

1 Answers  


Explain cannot copy (file name)- access is denied?

1 Answers  


Which protocol is working behind dhcp server? And what exactly dora does?

1 Answers  


Describe the actions taken by thread library to context switch between user level threads?

1 Answers  


Is kill ping a virus?

1 Answers  


What is multi programming?

1 Answers  


Explain what is the impact if dns server fails?

1 Answers  


Categories