public interface Pool
It is important to realize that some objects are cheaper to simply allow the garbage collector to take care of them. Therefore, only pool objects that are computationally expensive to create. Prime candidates would be Components, JDBC Connection objects, Socket connections, etc.
The interface is inspired by both the Mutex acquire/release and the structure of the ThreadLocal object. In fact, it would be trivial to implement a "ThreadLocal" pool.
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
acquire()
Acquire an instance of the pooled object.
|
java.lang.Object |
newInstance()
Create a new instance of the object being pooled.
|
void |
release(java.lang.Object pooledObject)
Release the instance of the pooled object.
|
java.lang.Object acquire()
throws java.lang.Exception
java.lang.Exception - if the Pool is not able to return an object.void release(java.lang.Object pooledObject)
pooledObject - The pooled object to release to the pool.java.lang.Object newInstance()
throws java.lang.Exception
java.lang.Exception - if the instance cannot be created