Within commons-pool, I'd like to propose adding the following method to the ObjectPool
interface:
public void invalidateObject(Object obj);
This would be used to address the situation in which you borrow an object from the
pool, and then upon use, discover that it is invalid, at which point you need to get
another one.
i.e.:
ObjectPool pool = new GenericObjectPool(...);
boolean success = false;
while (!success) {
try {
SomeConnection sc = (SomeConnection)pool.borrowObject();
sc.someOperation();
success = true;
}
catch (SomeConnectionException e) {
pool.invalidateObject(sc);
}
}
Why not use PoolableObjectFactory's "validateObject" method you ask?
Well, that requires testing the Object either before or after you use it, which
results in an extra call on the object EVERY time you borrow it (or return it). This
is a problem when the operation required to do the testing is expensive.
I'll be happy to take a crack at an implementation if people think this is a good idea.
Does this seem like a good idea, or are there other ways to address this problem?
Thanks!
---
- Nayan Hajratwala
- Chikli Consulting LLC
- http://www.chikli.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>