1 28 29 package com.caucho.jca; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import java.lang.ref.SoftReference ; 35 import java.util.ArrayList ; 36 import java.util.logging.Logger ; 37 38 39 43 public class ThreadConnectionManager { 44 private static final L10N L = new L10N(ThreadConnectionManager.class); 45 private static final Logger log = Log.open(ThreadConnectionManager.class); 46 47 private static final ThreadLocal <ThreadConnectionManager> _threadManager 48 = new ThreadLocal <ThreadConnectionManager>(); 49 50 private ArrayList <SoftReference <PoolItem>> _activeConnections 51 = new ArrayList <SoftReference <PoolItem>>(); 52 53 56 public static ThreadConnectionManager getThreadManager() 57 { 58 return _threadManager.get(); 59 } 60 61 64 public static void setThreadManager(ThreadConnectionManager manager) 65 { 66 _threadManager.set(manager); 67 } 68 69 72 public static ThreadConnectionManager createThreadManager() 73 { 74 ThreadConnectionManager cm = _threadManager.get(); 75 76 if (cm == null) { 77 cm = new ThreadConnectionManager(); 78 _threadManager.set(cm); 79 } 80 81 return cm; 82 } 83 84 87 public static void addConnection(PoolItem conn) 88 { 89 createThreadManager().add(conn); 90 } 91 92 95 public static void removeConnection(PoolItem conn) 96 { 97 createThreadManager().remove(conn); 98 } 99 100 103 private void add(PoolItem conn) 104 { 105 _activeConnections.add(new SoftReference <PoolItem>(conn)); 106 } 107 108 111 private void remove(PoolItem conn) 112 { 113 for (int i = _activeConnections.size() - 1; i >= 0; i--) { 114 PoolItem aConn = _activeConnections.get(i).get(); 115 116 if (aConn == null || aConn == conn) 117 _activeConnections.remove(i); 118 } 119 } 120 } 121 | Popular Tags |