1 6 package org.jfox.ejb; 7 8 import java.util.ArrayList ; 9 import java.util.List ; 10 11 16 17 class StatefulManager { 18 private long sleepTime = 10000L; 20 private List pools = new ArrayList (); 21 22 public StatefulManager() { 23 this(StatefulObjectPool.MAX_LIFE_TIME / 6); 24 } 25 26 public StatefulManager(long sleepTime) { 27 this.sleepTime = sleepTime; 28 ManagerThread mthread = new ManagerThread("StatefulSessionBean LifecycleManager Thread"); 29 mthread.setDaemon(true); 30 mthread.start(); 31 } 32 33 public void manageIt(StatefulObjectPool pool) { 34 pools.add(pool); 35 } 36 37 40 public void unmanageIt(StatefulObjectPool pool) { 41 pools.remove(pool); 42 } 43 44 class ManagerThread extends Thread { 45 public ManagerThread(String name) { 46 super(name); 47 } 49 50 public void run() { 51 while(true) { 52 try { 53 sleep(sleepTime); 54 } 55 catch(InterruptedException e) { 56 e.printStackTrace(); 57 } 58 for(int i = 0; i < pools.size(); i++) { 59 ((StatefulObjectPool) pools.get(i)).lifecycleCheck(); 60 } 61 } 62 } 63 } 64 65 public static void main(String [] args) { 66 67 } 68 } 69 70 | Popular Tags |