再补充一下,我并没有在程序了指定或者使用下标,而且各位也看到了,是proxool连接池本身出现了错误,并不是我的程序报的错,我的程序报的错误是:[ERROR]2011-03-19 9:58:53.460 -> 【Class:org.hibernate.exception.SQLStateConverter】 【org.hibernate.exception.GenericJDBCException Cannot open connection】 at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110) at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162) at org.hibernate.loader.Loader.doQuery(Loader.java:390) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218) at org.hibernate.loader.Loader.doList(Loader.java:1593) at org.hibernate.loader.Loader.list(Loader.java:1577) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
没跟这事了?这BUG有人提出来了。http://sourceforge.net/tracker/?func=detail&aid=2371114&group_id=53958&atid=472195- ConnectionPool.java, line 184: If another thread or even multiple threads have incremented nextAvailableConnection right before this statement, you might get another IndexOutOfBoundsException (while catching this IndexOutOfBoundsException). ConnectionPool.java, line 430: Conceivably, the value of isConnectionPoolUp() changes inbetween testing it, first for acquiring and then for releasing the write lock. That would result in inconsistent states or even deadlocks.Some even smaller issues:- The code acquires/releases locks inside try/finally blocks. The recommended pattern is to acquire the lock right _before_ the try block, in case acquiring the lock fails for whatever reason.- ProxyConnection.java, line 284: The lock statusReadWriteLock is only ever used for getting and acquiring a write lock. That effectively seems the same as synchronizing the method.
<alias>hibernatePool</alias>
<driver-url>jdbc:db2://...</driver-url>
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
<driver-properties>
<property name="user" value="user"/>
<property name="password" value="password"/>
</driver-properties>
<!--最大连接数(默认5个),超过了这个连接数,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定 -->
<maximum-connection-count>400</maximum-connection-count>
<!--最小连接数(默认2个) -->
<minimum-connection-count>0</minimum-connection-count>
<!--proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒 -->
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!-- 如果housekeeper 检测到某个线程的活动时间大于这个数值.它将会杀掉这个线程.所以确认一下你的服务器的带宽.然后定一个合适的值.默认是5分钟,单位毫秒 -->
<maximum-active-time>172800000</maximum-active-time>
<!-- 一次产生连接的数量 -->
<simultaneous-build-throttle>10</simultaneous-build-throttle>
<!-- 连接最大生命时间 默认4小时 -->
<simultaneous-build-throttle>172800000</simultaneous-build-throttle>
<!-- 一个线程的最大寿命 -->
<maximum-connection-lifetime>172800000</maximum-connection-lifetime>
<!--最少保持的空闲连接数(默认2个) -->
<prototype-count>0</prototype-count>
<!--在使用之前测试 -->
<test-before-use>true</test-before-use>
<!--用于保持连接的测试语句 -->
<house-keeping-test-sql>select id from tablename</house-keeping-test-sql>
</proxool>
【org.hibernate.exception.GenericJDBCException Cannot open connection】
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
谢谢各位啊,请帮帮忙啊,帖子写得有点乱,但是意思是表达出来了:
我是用proxool连接池,中间层用了hibernate,指定用的连接池是proxool,最后是用hibernate框架提供的接口实例化,是在使用的hibernate去查询数据库的时候,报了以上的错误。
<minimum-connection-count>0</minimum-connection-count>
和
<!--最少保持的空闲连接数(默认2个) -->
<prototype-count>0</prototype-count>
值改改,两个都改成2看看
If another thread or even multiple threads have
incremented nextAvailableConnection right before
this statement, you might get another
IndexOutOfBoundsException (while catching this
IndexOutOfBoundsException).
ConnectionPool.java, line 430:
Conceivably, the value of isConnectionPoolUp()
changes inbetween testing it, first for acquiring
and then for releasing the write lock. That would
result in inconsistent states or even deadlocks.Some even smaller issues:- The code acquires/releases locks inside try/finally
blocks. The recommended pattern is to acquire
the lock right _before_ the try block, in case
acquiring the lock fails for whatever reason.- ProxyConnection.java, line 284:
The lock statusReadWriteLock is only ever used
for getting and acquiring a write lock. That
effectively seems the same as synchronizing
the method.
在org.logicalcobwebs.proxool.ConnectionPool类中的方法getConnection和expireConnection方法加同步,如果不想考虑性能,就直接加方法上吧,如果要考虑,就自己去读读源码,可以细化到for循环里。