thread pool એ ફરીવપરાતા worker threads નો એક નિશ્ચિત set છે જે shared work queue માંથી tasks ખેંચે છે. તે દરેક task દીઠ thread બનાવવાના ખર્ચને ટાળે છે અને સમાંતર threads ની સંખ્યાને cap કરે છે.
શા માટે વાપરવો
Threads બનાવવા અને નષ્ટ કરવા મોંઘું છે (stack allocation, OS scheduling setup), અને unbounded thread creation memory ને ખતમ કરે છે અને context-switch thrashing કરાવે છે. pool creation ખર્ચને amortize કરે છે અને concurrency ને bound કરે છે.
tasks → [ work queue ] → worker 1
worker 2 (N fixed workers pull & run)
worker 3
