See discussion at http://code.google.com/p/guava-libraries/issues/detail?id=683.
This API is inspired by that proposed by kevinb@google.com
There are two ways to use the pool.
Passive:
Pool<Expensive> pool = ...
Lease<Expensive> lease = pool.leaseObject();
try {
Expensive o = lease.leasedObject();
doSomethingWith(o);
} finally {
lease.close();
}
Or active:
Pool<Expensive> pool = ...
pool.exec(
new Function<Expensive,Void>() {
public Void apply(Expensive o) {
doSomethingWith(o);
return null;
}
});