liveBook · Manning

Thread pool

As explained in Go in Action, Second Edition

A thread pool is a managed collection of reusable worker threads that execute submitted tasks.

A thread pool, called a worker pool in Go, processes many independent tasks concurrently while limiting parallelism. Fixed worker goroutines pull jobs from a shared channel, distributing bursts of work without exhausting resources. section 9.5

Model the pool as a queue and a set of workers. Each worker loops over the shared channel, performs the task, and waits for the next job; the pool exposes submission and shutdown operations. section 9.5.1

Feed-ingestion worker pool

A feed-ingestion service can create a buffered queue, start three workers, and submit feed URLs through Submit. Each worker fetches URLs with a 30-second context timeout. Closing the queue through Stop lets workers exit cleanly, while embedding the pool in App keeps submission separate from execution. section 9.5.1

Figure 9.2 Worker pools ingest incoming messages across multiple processes.

Visualizes workers consuming incoming messages across processes, clarifying how queued work is distributed. section 9.5.1

How Go in Action, Second Edition covers it

How deep it goes
Implements workers, a buffered shared channel, configurable pool size, submission, application integration, and shutdown.
Examples
Uses feed URLs, a buffered queue, three workers, timed feed fetching, an App-owned pool, and explicit Stop shutdown.
What it assumes
Assumes familiarity with Go concurrency, especially goroutines and channels, while applying them to queued work and controlled parallelism.
What you can do after
Build it from scratch using Go goroutines, channels, configurable workers, context timeouts, and explicit channel closure.
How it connects
Connects goroutines and channels with context.Context, pipelines, fan-in/fan-out, cancellation, error handling, and race detection.

Also explained in

Compare how 10 books explain thread pool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Action, Second Edition. The section links point to the parts of the book it draws on.