061 return pool.getConnection();
062 }
063 return null;
064 }
065
066 /**
067 * 获得一个可用连接.若没有可用连接,且已有连接数小于最大连接数限制,
068 * 则创建并返回新连接.否则,在指定的时间内等待其它线程释放连接.
069 *
070 * @param name 连接池名字
071 * @param time 以毫秒计的等待时间\\r
072 * @return Connection 可用连接或null
073 */
074 public Connection getConnection(String name, long time) {
075 DBConnectionPool pool = (DBConnectionPool) pools.get(name);
076 if (pool != null) {
077 return pool.getConnection(time);
078 }
079 return null;
080 }
081
082 /**
083 * 关闭所有连接,撤销驱动程序的注册\\r
084 */
085 public synchronized void release() {
086 // 等待直到最后一个客户程序调用
087 if (--clients != 0) {
088 return;
089 }
090
091 Enumeration allPools = pools.elements();
092 while (allPools.hasMoreElements()) {
093 DBConnectionPool pool = (DBConnectionPool
) allPools.nextElement();
094 pool.release();
095 }
096 Enumeration allDrivers = drivers.elements();
097 while (allDrivers.hasMoreElements()) {
098 Driver driver = (Driver) allDrivers.nextElement();
099 try {
100 DriverManager.deregisterDriver(driver);
101 log("撤销JDBC驱动程序 " + driver.getClass().getName()+"的注册\\\");
102 }
103 catch (SQLException e) {
104 log(e, "无法撤销下列JDBC驱动程序的注册: " + driver.getClass().getName());
105 }
106 }
107 }
108
109 /**
110 * 根据指定属性创建连接池实例.
111 *
112 * @param props 连接池属性
113 */
114 private void createPools(Properties props) {
115 Enumeration propNames = props.propertyNames();
116 while (propNames.hasMoreElements()) {
117 String name = (String) propNames.nextElement();
118 if (name.endsWith(".url")) {
119 String poolName = name.substring(0, name.lastIndexOf("."));
120 String url = props.getProperty(poolName + ".url");
121 if (url == null) {
122 log("没有为连接池" + poolName + "指定URL");
123 continue;
124 }
125 String user = props.getProperty(poolName + ".user");
126 String password = props.getProperty(poolName + ".password");
127 String maxconn = props.getProperty(poolName + ".maxconn", "0");
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页