public class WdzPoolableObjectFactory implements PoolableObjectFactory {
/** * 創建對象實例。同時可以分配這個對象適用的資源。 * **/ public Object makeObject() throws Exception { return new Student(); };
/** * 銷毀對象,實際上提供了釋放對象占用資源的接口。 * destroyObject is invoked on every instance when it is being "dropped" * from the pool (whether due to the response from validateObject, * or for reasons specific to the pool implementation.) * */ public void destroyObject(Object obj) throws Exception { }
/*** * 這個方法一般在 activateObject 方法執行后調用 * 檢查對象的有效性 * validateObject is invoked in an implementation-specific fashion to * determine if an instance is still valid to be returned by the pool. * It will only be invoked on an "activated" instance. * **/ public boolean validateObject(Object obj) { return true; }
/** * 激活一個對象。 * activateObject is invoked on every instance before it is returned from the pool. * **/ public void activateObject(Object obj) throws Exception { }
/** * 掛起一個對象 * passivateObject is invoked on every instance when it is returned to the pool * **/ public void passivateObject(Object obj) throws Exception { if (obj instanceof Student) { ( (Student) obj).clear(); } } } package impl_genericobjectpool_test;