java.sql.SQLException: Already closed. at org.apache.commons.dbcp.PoolableConnection.close(PoolableC

java.sql.SQLException: Already closed.
    at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:77)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:180)
    at cn.com.jdbc.JdbcUtils_DBCP.release(JdbcUtils_DBCP.java:81)
    at cn.com.jdbc.Tools.update(Tools.java:27)
    at cn.com.Socket.ThreadReader.insert_num(ThreadReader.java:172)
    at cn.com.Socket.ThreadReader.othernum(ThreadReader.java:154)
    at cn.com.Socket.ThreadReader.read(ThreadReader.java:90)
    at cn.com.Socket.ThreadReader.Port(ThreadReader.java:59)
    at cn.com.Socket.ThreadReader.run(ThreadReader.java:25)
    at java.lang.Thread.run(Thread.java:744)

一上午了,一直报错,我明明都是在执行数据库操作之后关闭连接的。

程序书写绝对规范;

百度之后得到了两个建议:

一、

原因:

You're probably running into the fact that MYSQL closes connections  which have been open "too long". 
Probably if you make the request to the server again, you'll find that  it works because the connection is reopened. 

解决方法:

One way to deal with this is to add the following to your context.xml  Resource: 

validationQuery="select 1"  (基于mysql)

validationQuery="select 1 from dual"  (基于oracle)

(对我的程序没有用处)

二、

使用这个commons-dbcp-1.2.jar 时,当资源耗尽时会死锁程序,不往下执行,可怕。

我把jar换成 commons-dbcp-1.4.jar

  commons-pool-1.5.6.jar 之后,就没有报错了;

猜你喜欢

转载自blog.csdn.net/qq_37591637/article/details/83747587
今日推荐