3 回答

慕婉清6462132
TA貢獻1804條經(jīng)驗 獲得超2個贊
getDbConnection
public class DbConnection{ private static final int MAX_CONNS = 100; private static int totalConnections = 0; private static Set<DbConnection> availableConnections = new HashSet<DbConnection>(); private DbConnection(){ // ... totalConnections++; } public static DbConnection getDbConnection(){ if(totalConnections < MAX_CONNS){ return new DbConnection(); }else if(availableConnections.size() > 0){ DbConnection dbc = availableConnections.iterator().next(); availableConnections.remove(dbc); return dbc; }else { throw new NoDbConnections(); } } public static void returnDbConnection(DbConnection dbc){ availableConnections.add(dbc); //... }}

慕容708150
TA貢獻1831條經(jīng)驗 獲得超4個贊
價值 getInstance 新情況
添加回答
舉報
0/150
提交
取消