1. Thread pool saves us from the overhead of creating and destroying threads.
Creating a new thread has a certain resource cost, and so spawning many threads, each of which will perform a short task and then exit, means that the JVM may be doing more work and consuming more resources creating and destroying threads than actually doing useful work.
2. Thread pool helps us manage our application well when a flood of requests arrive.
How do you bound the resources used in executing tasks of a certain type? What would prevent you from spawning a thousand threads at once, if a flood of requests came in all of a sudden? Real-world server applications need to manage their resources more carefully than this. You need to limit the number of asynchronous tasks executing at once.
Friday, April 30, 2010
Subscribe to:
Posts (Atom)
