项目使用proxool做的JDBC连接池,每次在启动项目的时候,会抛出一下异常:
org.logicalcobwebs.proxool.ProxoolException: Attempt to refer to a unregistered pool by its alias 'HAIERDB' at org.logicalcobwebs.proxool.ConnectionPoolDefinition.doChange(ConnectionPoolDefinition.java:250) at org.logicalcobwebs.proxool.ConnectionPoolDefinition.<init>(ConnectionPoolDefinition.java:147) at org.logicalcobwebs.proxool.ProxoolFacade.registerConnectionPool(ProxoolFacade.java:96) at org.logicalcobwebs.proxool.ProxoolDriver.connect(ProxoolDriver.java:77) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:207) at com.listener.tools.ConnectDBUtil.connectDB(ConnectDBUtil.java:33) at com.listener.timer.AccessTimer.insertSQL(AccessTimer.java:122) at com.listener.timer.AccessTimer$1.run(AccessTimer.java:60) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) MYSQL ERROR:org.logicalcobwebs.proxool.ProxoolException: Attempt to refer to a unregistered pool by its alias 'HAIERDB'2015-1-6 14:36:22 org.apache.coyote.http11.Http11AprProtocol start通过异常可以简单理解,此连接池已经创建了同名的alias,出现冲突了。
问题原因:
服务在启动的时候,proxool会创建相应的连接池,但是如果此时servlet调用另外的一个线程同事去创建线程池,那么在并发的情况下,就会出现这个问题。
如下程序启动是调用下面方法
public class AccessTimer implements ServletContextListener { private Logger logger = Logger.getLogger(AccessTimer.class); private final static String seq = "','"; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式 @Override public void contextInitialized(ServletContextEvent paramServletContextEvent) { access(); }
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
或者在配置文件中增加线程启动的优先级
如下参考:http://blog.csdn.net/qq799499343/article/details/8625100