博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

使用proxool的异常

Posted on 2012-10-16 15:24  feng1825  阅读(8217)  评论(0编辑  收藏  举报

proxool配置如下:

proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
    <proxool>
        <alias>dbname</alias> <!--数据源的别名-->  
        <driver-url>jdbc:mysql://localhost:3306/mysqltest?useUnicode=true&amp;characterEncoding=utf8</driver-url><!--url连接-->
        <driver-class>com.mysql.jdbc.Driver</driver-class> <!--驱动类-->
        <driver-properties>
            <property name="user" value="root" /> <!--用户名-->
            <property name="password" value="root" /><!--密码-->
        </driver-properties> 
    <!--最大连接数(默认5个),超过了这个连接数,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定 -->  
        <maximum-connection-count>100</maximum-connection-count> 
       <!--最小连接数(默认2个)--> 
        <minimum-connection-count>10</minimum-connection-count> 
       <!--proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒-->  
        <house-keeping-sleep-time>90000</house-keeping-sleep-time>
    <!--没有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受--> 
        <maximum-new-connections>10</maximum-new-connections> 
      <!--最少保持的空闲连接数(默认2个)-->  
        <prototype-count>5</prototype-count> 
    </proxool>
</something-else-entirely> 
hibernate-context.xml
<beans>
....添加
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" >
        <property name="alias">
            <value>dbname</value>
        </property>
        <property name="driver">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="driverUrl">
            <value>jdbc:mysql://localhost:3306/mysqltest?useUnicode=true&amp;characterEncoding=utf8</value>
        </property>
        <property name="user">
            <value>root</value>
        </property>
        <property name="password">
            <value>root</value>
        </property>
        <property name="minimumConnectionCount">
            <value>10</value>
        </property>
        <property name="maximumConnectionCount">
            <value>100</value>
        </property>
        <property name="prototypeCount">
            <value>5</value>
        </property>
    </bean>   
....
</beans>
web.xml
<web-app>
....添加
<servlet>
        <servlet-name>ServletConfigurator</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.configuration.ServletConfigurator
        </servlet-class>
        <init-param>
            <param-name>xmlFile</param-name>
            <param-value>WEB-INF/proxool.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>Admin</servlet-name>
        <servlet-class>
            org.logicalcobwebs.proxool.admin.servlet.AdminServlet
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Admin</servlet-name>
        <url-pattern>/admin</url-pattern>
    </servlet-mapping>
    <!-- 配置受保护域,只有Tomcat管理员才能察看连接池的信息 -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>proxool</web-resource-name>
            <url-pattern>/admin</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>manager</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>proxool manager Application</realm-name>
    </login-config>
    <security-role>
        <description>
            The role that is required to log in to the Manager Application
        </description>
        <role-name>manager</role-name>
    </security-role>
....
</web-app>

添加jar包
proxool-0.9.1.jar
proxool-cglib.jar

出现异常,异常信息如下所示:

exception1
2012-10-12 15:23:58 ERROR interceptor.TransactionInterceptor (TransactionAspectSupport.java:287) - Application exception overridden by rollback exception
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select contentflo0_.id as id17_, contentflo0_.contentid as contentid17_, contentflo0_.flowtaskid as flowtaskid17_ from contentflowtask contentflo0_, content content1_ where contentflo0_.contentid=content1_.id and contentflo0_.contentid=1830 and content1_.isdelete=0 order by contentflo0_.id desc]; SQL state [08003]; error code [0]; No operations allowed after connection closed.

Connection was closed explicitly by the application at the following location:

** BEGIN NESTED EXCEPTION ** 

java.lang.Throwable

STACKTRACE:

java.lang.Throwable
    at com.mysql.jdbc.Connection.close(Connection.java:1123)
    at org.logicalcobwebs.proxool.AbstractProxyConnection.reallyClose(AbstractProxyConnection.java:173)
    at org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:413)
    at org.logicalcobwebs.proxool.HouseKeeper.sweep(HouseKeeper.java:139)
    at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:39)


** END NESTED EXCEPTION **

; nested exception is java.sql.SQLException: No operations allowed after connection closed.

Connection was closed explicitly by the application at the following location:

** BEGIN NESTED EXCEPTION ** 

java.lang.Throwable

STACKTRACE:

java.lang.Throwable
    at com.mysql.jdbc.Connection.close(Connection.java:1123)
    at org.logicalcobwebs.proxool.AbstractProxyConnection.reallyClose(AbstractProxyConnection.java:173)
    at org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:413)
    at org.logicalcobwebs.proxool.HouseKeeper.sweep(HouseKeeper.java:139)
    at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:39)


** END NESTED EXCEPTION **


java.sql.SQLException: No operations allowed after connection closed.

Connection was closed explicitly by the application at the following location:

** BEGIN NESTED EXCEPTION ** 

java.lang.Throwable

STACKTRACE:

java.lang.Throwable
    at com.mysql.jdbc.Connection.close(Connection.java:1123)
    at org.logicalcobwebs.proxool.AbstractProxyConnection.reallyClose(AbstractProxyConnection.java:173)
    at org.logicalcobwebs.proxool.ConnectionPool.removeProxyConnection(ConnectionPool.java:413)
    at org.logicalcobwebs.proxool.HouseKeeper.sweep(HouseKeeper.java:139)
    at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:39)


** END NESTED EXCEPTION **


    at com.mysql.jdbc.Connection.checkClosed(Connection.java:2474)
    at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1370)
    at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1350)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.logicalcobwebs.proxool.ProxyConnection.invoke(ProxyConnection.java:68)
    at org.logicalcobwebs.cglib.proxy.Proxy$ProxyImpl$$EnhancerByCGLIB$$edd30696.prepareStatement(<generated>)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
    at org.hibernate.loader.Loader.doQuery(Loader.java:661)
    at or.....
exception2
2012-10-12 16:16:19 ERROR transaction.JDBCTransaction (JDBCTransaction.java:67) - JDBC begin failed
java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. 
It has been automatically closed by Proxool for some reason (see logs).
    at org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:207)
    at org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:87)
    at $java.sql.Connection$$EnhancerByProxool$$3f2ab9d8.getAutoCommit(<generated>)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1319)
    ......

出现异常结果都表明使用proxool连接时出现连接超时,具体原因如下:
<maximum-active-time>一个活动连接最大活动时间默认5分钟,如果超过这个时间则proxool连接会自动断开。

即在proxool.xml中修改:

proxool.xml
<?xml version="1.0" encoding="UTF-8"?>
<something-else-entirely>
    <proxool>
        <alias>dbname</alias> 
        <driver-url>jdbc:mysql://localhost:3306/mysqltest?useUnicode=true&amp;characterEncoding=utf8</driver-url>
        <driver-class>com.mysql.jdbc.Driver</driver-class> 
        <driver-properties>
            <property name="user" value="root" /> 
            <property name="password" value="root" />
        </driver-properties> 
    <!--最大连接数(默认5个),超过了这个连接数,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定 -->  
        <maximum-connection-count>100</maximum-connection-count> 
       <!--最小连接数(默认2个)--> 
        <minimum-connection-count>10</minimum-connection-count> 
    <!--没有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受--> 
        <maximum-new-connections>10</maximum-new-connections> 
      <!--最少保持的空闲连接数(默认2个)-->  
        <prototype-count>5</prototype-count>
    <!--一个活动连接最大活动时间默认5分钟-->
        <maximum-active-time>3600000</maximum-active-time>
    <!--自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->
            <house-keeping-sleep-time>60000</house-keeping-sleep-time>  
    <!--Test SQL(SELECT getDate()) -->
            <house-keeping-test-sql>select sysdate() </house-keeping-test-sql>
    </proxool>
</something-else-entirely>