At this point, you’ve read some 70 or so pages of reasonably plausible material on threading. But, speaking from personal experience, it’s almost impossible to read 70 pages of material on threading and actually understand all of it on the first reading.
The point of this section is to introduce a fairly complex and sophisticated piece of code that involves threading. If you understand this example, how it works, and why it’s built the way it is, then you’ve got a reasonable grasp of this material and how to use threads in your applications. If, however, this seems like an incredibly byzantine and opaque piece of code, then you may want to reread those 70 pages or grab a copy of one of the references.
Pooling is an important idiom in designing scalable applications. The central idea is that there is a resource, encapsulated by an object, with the following characteristics:
It is difficult to create the resource, or doing so consumes other scarce resources.
The resource can be reused many times.
You frequently need more than one instance of the resource because there are many threads that perform tasks involving this type of resource (I will call these threads the client threads).
The canonical example of a resource that
ought to be pooled is a database connection. In
Java, database connections are embodied as
instances of an implementation of the
java.sql.Connection interface. A database vendor will supply a class that implements ...