日期:2014-05-16  浏览次数:20577 次

seesion不及时释放导致的数据库连接问题
这几天正在开发的系统,出现了严重的数据库连接问题,时常因挂掉,

警告: SQL Error: 0, SQLState: null
2011-1-12 11:20:40 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: Listener refused the connection with the following error:
ORA-12518, TNS:listener could not hand off client connection
The Connection descriptor used by the client was:
192.168.1.167:1521:orcl

2011-1-12 11:20:40 org.hibernate.cfg.SettingsFactory buildSettings
警告: Could not obtain connection metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12518, TNS:listener could not hand off client connection
The Connection descriptor used by the client was:
192.168.1.167:1521:orcl

排除了数据库本身的问题后,只能从自身找问题了。

	<filter>
		<filter-name>OpenSessionInViewFilter</filter-name>    
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
	</filter>
	<filter-mapping>
		<filter-name>OpenSessionInViewFilter</filter-name>    
		<url-pattern>/message/*</url-pattern> 
	 </filter-mapping>

问题就是配置只过滤了部分数据连接。导致还有大量的hibernate session没有及时关闭。

但有时候还是有问题,又从网上找了这么一段,参考:
引用

原因一般为:客户连接到监听器后,监听器把客户重定向到调度程序端口,由于操作系统问题,这些连接会被拒绝。
要解决这个问题,只需要在LISTENER.ORA的头部加入这一行DIRECT_HANDOFF_TTC_LISTENER = OFF即可。

在listener.ora文件加上一句 DIRECT_HANDOFF_TTC_LISTENER = OFF

然后重启监听服务

lsnrctl stop
lsnrctl start