Friday, 22 April 2016

What is the benefit of using Thread pools ?


Rather than creating new thread for each task , you can have a thread pulled out from the pool and assigned to the task.
After finishing the task, the thread will join back the pool.
It reduces response time as the threads are already created.

Thread pools are fixed in size on construction. All threads are started and goes to wait state.
When all threads are assigned to some tasks (empty pool) , new service will be rejected or will be waiting for a thread to be free.

Java 5 comes with built-in thread pool in form of class ThreadPoolExecutor.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.