Thread pool pattern


Thread pool pattern

In the thread pool pattern in programming, a number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads. As soon as a thread completes its task, it will request the next task from the queue until all tasks have been completed. The thread can then terminate, or sleep until there are new tasks available.

The number of threads used is a parameter that can be tuned to provide the best performance.Additionally, the number of threads can be dynamic based on the number of waiting tasks.For example, a web server can add threads if numerous web page requests come in and can remove threads when those requests taper down.The cost of having a larger thread pool is increased resource usage.The algorithm that determines when creating or destroying threads will have an impact on the overall performance:
* create too many threads and resources are wasted and time also wasted creating the unused threads
* destroy too many threads and more time will be spent later creating them again
* creating threads too slowly might result in poor client performance (long wait times)
* destroying threads too slowly may starve other processes of resourcesThe algorithm chosen will depend on the problem and the expected usage patterns.

The advantage of using a thread pool over creating a new thread for each task, is that thread creation and destruction overhead is negated, which may result in better performance and better system stability.

When implementing this pattern, the programmer should ensure thread-safety of the queue.

Typically, a thread pool executes on a single processor. However, thread pools are conceptually related to server farms in which a master process distributes tasks to worker processes on different computers, in order to increase the overall throughput. Embarrassingly parallel problems are highly amenable to this approach.

ee also

*Concurrency pattern
*Parallelization
*Server farm

External links

*Article " [http://today.java.net/pub/a/today/2008/01/31/query-by-slice-parallel-execute-join-thread-pool-pattern.html Query by Slice, Parallel Execute, and Join: A Thread Pool Pattern in Java] " by Binildas C. A.
*Article " [http://www-128.ibm.com/developerworks/java/library/j-jtp0730.html Thread pools and work queues] " by Brian Goetz
*Article " [http://www.codeproject.com/threads/thread_pooling.asp A Method of Worker Thread Pooling] " by Pradeep Kumar Sahu
*Article " [http://codeproject.com/threads/work_queue.asp Work Queue] " by Uri Twig
*Article " [http://codeproject.com/threads/Joshthreadpool.asp Windows Thread Pooling and Execution Chaining] "
*Article " [http://www.codeproject.com/cs/threads/smartthreadpool.asp Smart Thread Pool] " by Ami Bar
*Article " [http://msdn.microsoft.com/library/en-us/dndotnet/html/progthrepool.asp Programming the Thread Pool in the .NET Framework] " by David Carmona
*Article " [http://www.yoda.arachsys.com/csharp/threads/threadpool.shtml The Thread Pool and Asynchronous Methods] " by Jon Skeet
*Paper " [http://www.cs.wustl.edu/~schmidt/PDF/OM-01.pdf Optimizing Thread-Pool Strategies for Real-Time CORBA] " by Irfan Pyarali, Marina Spivak, Douglas C. Schmidt and Ron Cytron


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Object pool pattern — For the article about a general pool see Pool (Computer science) In computer programming, an object pool is a software design pattern. An object pool is a set of initialised objects that are kept ready to use, rather than allocated and destroyed… …   Wikipedia

  • Pool — may refer to: Bodies of water*Plunge pool, small, deep body of water *The River Pool, river in England, tributary to the River Ravensbourne *Reflecting pool, shallow pool of water designed to reflect a structure and its surroundings: **Capitol… …   Wikipedia

  • Thread (computer science) — This article is about the concurrency concept. For the multithreading in hardware, see Multithreading (computer architecture). For the form of code consisting entirely of subroutine calls, see Threaded code. For other uses, see Thread… …   Wikipedia

  • Pool (computer science) — A pool in computer science is a set of initialised resources that are kept ready to use, rather than allocated and destroyed on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When… …   Wikipedia

  • Concurrency pattern — In software engineering, concurrency patterns are those types of design patterns that deal with multi threaded programming paradigm. Examples of this class of patterns include: Active Object[1][2] Balking pattern Double checked locking pattern… …   Wikipedia

  • Software design pattern — In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into code. It is a… …   Wikipedia

  • Command pattern — In object oriented programming, the command pattern is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object… …   Wikipedia

  • Object pool — In computer programming, an object pool is a software design pattern. An object pool is a set of initialised objects that are kept ready to use, rather than allocated and destroyed on demand. A client of the pool will request an object from the… …   Wikipedia

  • Multiton pattern — In software engineering, the multiton pattern is a design pattern similar to the singleton, which allows only one instance of a class to be created. The multiton pattern expands on the singleton concept to manage a map of named instances as key… …   Wikipedia

  • Шаблон проектирования — У этого термина существуют и другие значения, см. Паттерн. В разработке программного обеспечения, шаблон проектирования или паттерн (англ. design pattern) повторимая архитектурная конструкция, представляющая собой решение проблемы… …   Википедия