- 浏览: 77939 次
- 性别:
- 来自: 广州
文章分类
最新评论
import java.sql.Connection; import java.sql.DriverManager; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; import oracle.jdbc.OracleDriver; import oracle.jdbc.pool.OracleOCIConnectionPool; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; import com.logging.LogUtil; import com.common.Constants; import com.common.Util; import com.ui.AbstractPlugin; /** * PooledConnectionManager * */ public class PooledConnectionManager { /** * String decryptFileName */ private String decryptFileName = "OCIFileName"; /** * PooledConnectionManager instance */ private static PooledConnectionManager instance = null; /** * Map poolMap */ private static Map poolMap = null; /** * String defaultPoolName */ private static String defaultPoolName = null; /** * String debugInfoFlag */ private static String debugInfoFlag = "false"; /** * PooledConnectionManager * @return instance * @throws Exception */ public static PooledConnectionManager getInstance() throws Exception { if(instance == null) { instance = new PooledConnectionManager(); } return instance; } /** * PooledConnectionManager * @throws Exception */ protected PooledConnectionManager() throws Exception { if (poolMap == null) { poolMap = new HashMap(); SAXReader reader = new SAXReader(); Document document = reader.read(AbstractPlugin.class.getResourceAsStream(Constants.CONFIG_COMMON_PATH)); Element ociPoolsEle = (Element) document.getRootElement().element(Constants.OCIPOOLS); if("true".equals(ociPoolsEle.attributeValue("debugInfo"))) { debugInfoFlag = "true"; } //Get the name of decryptConsole String decryptConsole = ociPoolsEle.elementTextTrim(Constants.OCIPOOL_DECRYPT_CONSOLE); Iterator iter = ociPoolsEle.elementIterator("OCIPool"); DriverManager.registerDriver(new OracleDriver()); while (iter.hasNext()) { Element recordEle = (Element) iter.next(); if("true".equals(recordEle.attributeValue("default"))) { defaultPoolName = recordEle.attributeValue("name"); } Properties poolPro = new Properties(); poolPro.put(OracleOCIConnectionPool.CONNPOOL_MIN_LIMIT, recordEle.elementTextTrim(Constants.OCIPOOL_MINLIMIT_PRO)); poolPro.put(OracleOCIConnectionPool.CONNPOOL_MAX_LIMIT, recordEle.elementTextTrim(Constants.OCIPOOL_MAXLIMIT_PRO)); poolPro.put(OracleOCIConnectionPool.CONNPOOL_INCREMENT, recordEle.elementTextTrim(Constants.OCIPOOL_INCREMENT_PRO)); poolPro.put(OracleOCIConnectionPool.CONNPOOL_TIMEOUT, recordEle.elementTextTrim(Constants.OCIPOOL_CONIDLETIME_PRO)); //Decoding the password String password = Util.decrypt(recordEle.elementTextTrim(Constants.OCIPOOL_PASSWORD_PRO), decryptFileName, decryptConsole); OracleOCIConnectionPool cpool = new OracleOCIConnectionPool(recordEle.elementTextTrim(Constants.OCIPOOL_USERNAME_PRO), password, recordEle.elementTextTrim(Constants.OCIPOOL_URL_PRO), poolPro); poolMap.put(recordEle.attributeValue("name"), cpool); } } } /** * OracleOCIConnectionPool * @param poolName * @return cpool * @throws Exception */ public OracleOCIConnectionPool getConnectionPool(String poolName) throws Exception { OracleOCIConnectionPool cpool = (OracleOCIConnectionPool)poolMap.get(poolName); if(cpool == null) { throw new NoSuchPoolException("There is no OCI pool named \"" + poolName + "\"."); } if(debugInfoFlag.equals("true")) { this.printPoolInfo(poolName); } return cpool; } /** * OracleOCIConnectionPool * @return cpool * @throws Exception */ public OracleOCIConnectionPool getConnectionPool() throws Exception { OracleOCIConnectionPool cpool = null; if(defaultPoolName != null) { //Get the default pool which is assigned. cpool = (OracleOCIConnectionPool)poolMap.get(defaultPoolName); if(debugInfoFlag.equals("true")) { this.printPoolInfo(defaultPoolName); } } else { //If there is no default pool to be assigned,get the first pool. if(poolMap.keySet() != null) { cpool = (OracleOCIConnectionPool)poolMap.get(poolMap.keySet().toArray()[0]); if(debugInfoFlag.equals("true")) { this.printPoolInfo((String)poolMap.keySet().toArray()[0]); } } } return cpool; } /** * getConnection * @param poolName * @return conn * @throws Exception */ public Connection getConnection(String poolName) throws Exception { return this.getConnectionPool(poolName).getConnection(); } /** * getConnection * @return conn * @throws Exception */ public Connection getConnection() throws Exception { OracleOCIConnectionPool cpool = this.getConnectionPool(); if(cpool != null) { return cpool.getConnection(); } return null; } /** * printPoolInfo * @param poolName * @throws Exception */ private void printPoolInfo(String poolName) throws Exception { OracleOCIConnectionPool cpool = (OracleOCIConnectionPool)poolMap.get(poolName); LogUtil.info(this.getClass(), "Current OCI connection pool is: " + poolName + "."); LogUtil.info(this.getClass(), "Pool size is: " + cpool.getPoolSize() + "."); LogUtil.info(this.getClass(), "Active size is: " + cpool.getActiveSize() + "."); LogUtil.info(this.getClass(), "Min pool size limit is: " + cpool.getMinLimit() + "."); LogUtil.info(this.getClass(), "Max pool size limit is: " + cpool.getMaxLimit() + "."); } }
发表评论
-
HTTPClient
2012-12-21 21:11 0public class RenRen { // The ... -
Export To Excel - Testing
2012-12-18 13:15 0MainTest ..... Map configM ... -
Export To Excel - ExcelUtils.java [Version 0.2]
2012-12-18 13:11 9import java.io.BufferedReader; ... -
Export To Excel - Action Oupt Excel
2012-11-23 13:49 10public String doAction(Work ... -
Export To Excel - ExcelUtils.java
2012-12-17 16:31 3import java.io.BufferedReader; ... -
Export To Excel - ExcelDAO.java
2012-12-18 12:55 5import java.sql.CallableStateme ... -
Export To Excel - commonExcelStyle.css
2012-12-18 12:55 6body { FONT-FAMILY: "Ari ... -
Export To Excel - ExcelConstants.java
2012-12-18 12:55 5/** * <p><b> * ... -
Export To Excel - ExcelRowList.java
2012-12-18 09:55 5import java.util.ArrayList; im ... -
Export To Excel - ExcelRowItem.java
2012-12-17 16:32 7import java.util.ArrayList; im ... -
Export To Excel - ExcelInfo.java
2012-11-23 13:50 8/** * <p><b> * ... -
Export To Excel - ExcelColList.java
2012-11-23 13:50 6import java.util.ArrayList; im ... -
Export To Excel - ExcelColItem.java
2012-11-23 13:50 11Version 0.1 import java.uti ... -
Export To Excel - ExcelCellItem.java
2012-11-23 13:49 7public class ExcelCellItem { ... -
Util
2012-12-17 16:32 675import java.io.BufferedReader; ... -
DMSUtil
2012-12-17 16:31 706import java.io.ByteArrayInputSt ... -
FloatValidator
2012-10-05 13:42 771public class FloatValidator ext ... -
XmlHelper
2012-08-31 09:33 1266import java.io.ByteArrayInputSt ... -
XMLEncode
2012-08-30 18:43 1053public class XMLEncode implemen ... -
tagUtil
2012-08-30 18:42 875import java.util.Map; public ...
相关推荐
你可以查看`com.mchange.v2.c3p0`包下的类,如`CommingledPool`、`PooledConnectionManager`和`ManagedConnectionFactory`等,了解它们在连接池管理中的角色。 `c3p0-0.9.1.2.bin`可能包含编译后的库文件或者二进制...
3. **连接生命周期管理**:关注`com.mchange.v2.c3p0.impl`包内的`PooledConnectionManager`和`PoolBackedDataSource`等类,理解连接的创建、分配、回收和关闭流程。 4. **异常处理机制**:查看`...
源码中的关键类如`PooledConnectionManager`、`PoolableConnectionFactory`和`PoolConfig`分别对应连接管理、池化连接工厂和配置信息。 **五、最佳实践** 1. **合理设置参数**: 根据应用的并发量和数据库性能调整...
例如,`PooledConnectionManager`类负责管理所有连接,`PoolableConnection`类代表池中的一个连接实例,`Combiner`类用于合并多个连接池的配置等。 **五、应用场景** c3p0常用于中小型的Java Web应用,与Spring等...
- **PooledConnectionManager**: 连接管理器,负责创建、维护和销毁数据库连接,以及连接池的初始化和清理工作。 - **PoolConfig**: 存储所有配置属性的类,例如最大连接数、最小连接数、超时时间等。 - **TestKit...