1 14 15 package org.quickserver.util.pool.thread; 16 17 import org.apache.commons.pool.BasePoolableObjectFactory; 18 19 25 public class ThreadObjectFactory extends BasePoolableObjectFactory { 26 private ClientPool pool; 27 private static int instanceCount = 0; 28 private int id = -1; 29 30 public ThreadObjectFactory() { 31 super(); 32 id = ++instanceCount; 33 } 34 35 public void setClientPool(ClientPool pool) { 36 this.pool = pool; 37 } 38 39 public Object makeObject() { 41 ClientThread ct = new ClientThread(pool, id); 42 ct.start(); 43 return ct; 44 } 45 46 public void passivateObject(Object obj) { 48 ((ClientThread)obj).clean(); 49 } 50 51 public void activateObject(Object obj) { 53 } 54 55 public void destroyObject(Object obj) { 57 if(obj==null) return; 58 Thread thread = (Thread ) obj; 59 thread.interrupt(); 60 thread = null; 61 } 62 63 public boolean validateObject(Object obj) { 65 if(obj==null) return false; 66 Thread thread = (Thread )obj; 67 return thread.isAlive(); 68 } 69 } 70 | Popular Tags |