在项目中碰到了一个应用异常,从表象来看应用僵死。查看Weblogic状态为Running,内存无溢出,可是出现屡次线程堵塞。查看Weblogic日志,发现程序出现屡次Time Out。html
咱们知道,Weblogic会自动检测线程运行超时,当超过特色时间(默认600S),即认为此线程为堵塞线程。在日志中发现屡次堵塞线程,经过查找资料,发现Weblogic在发生屡次线程堵塞后,会自动把应用挂起。默认次数为15次。java
是什么形成了线程堵塞呢?经过进一步分析日志,咱们发如今线程堵塞以前,发生了屡次java.sql.SQLRecoverableException: Closed Connection异常。异常状况:sql
从表现来看是数据库链接出了异常。咱们对数据库和网络进行了分析,肯定数据库和网络都无异常。咱们的另一个应用在Weblogic运行没有相似问题。数据库
最后在Oracle的论坛上找到了问题的根结,因为咱们的应用是本身开发的数据库链接池,应用和数据库之间有一层防火墙。防火墙策略是对于1800s未使用的Socket链接将自动关闭。Oracle的日志中也发现Socket异常关闭的异常。咱们对应用进行了调整,当链接池中的链接15分钟不用时,自动回收,问题解决。网络
http://blog.csdn.net/gavinloo/article/details/12206763app
当数据库链接池中的链接被建立而长时间不使用的状况下,该链接会自动回收并失效,但客户端并不知道,在进行数据库操做时仍然使用的是无效的数据库链接,这样,就致使客户端程序报“ java.sql.SQLException: Io 异常: Connection reset” 或“java.sql.SQLException 关闭的链接”异常。post
在配置数据源后面加上测试
<property name="validationQuery" value="select * from dual"/>this
配置后,客户端在使用一个无效的链接时会先对该链接进行测试,若是发现该链接已经无效,则从新从链接池获取有效数据库链接来使用。url
void setQueryTimeout(int seconds) throws SQLException
Statement
object to execute to the given number of seconds. If the limit is exceeded, an
SQLException
is thrown. A JDBC driver must apply this limit to the
execute
,
executeQuery
and
executeUpdate
methods. JDBC driver implementations may also apply this limit to
ResultSet
methods (consult your driver vendor documentation for details).
seconds
- the new query timeout limit in seconds; zero means there is no limit
SQLException
- if a database access error occurs, this method is called on a closed
Statement
or the condition seconds >= 0 is not satisfied
getQueryTimeout()