网站发布到服务器上隔一段时间就访问不到数据库了,重启下IIS就好了,请问这个是什么问题啊 跪求

网站发布到服务器上隔一段时间就访问不到数据库了,重启下IIS就好了,请问这个是什么问题啊 跪求,第1张

一般是IIS部署的网站使用的应用程序池需要回收缓存了,打开该网站所使用的应用程序池(如果没有特别设置,一般用的DefaultAppPool),选择高级设置,里面有一项回收时间间隔默认1740(分钟,约29小时),改短一点,例如120(分钟)。

您好,发现了问题,我首先在c3p0上加上 调试信息的配置 :

c3p0.debugUnreturnedConnectionStackTraces=true

c3p0.unreturnedConnectionTimeout=90 (我的连接超时时间是60s,所以这设置了90s)

applicationContext数据源配置增加响应配置

<property name="breakAfterAcquireFailure" value="${c3p0.breakAfterAcquireFailure}" />

<property name="testConnectionOnCheckout" value="${c3p0.testConnectionOnCheckout}" />

果然发现很多未回收的连接,正常情况下超时未回收的连接会有一些,但是不会这么多啊。

经查资料在hibernate sessionFacory中增加配置(http://hi.baidu.com/austincao/item/fc9907da3d854e44fa576861)

Spring3.1去掉了HibernateDaoSupport类。hibernate4需要通过getCurrentSession()获取session。 并且设置

<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>

在Spring @Transactional声明式事务管理,”currentSession”的定义为: 当前被 Spring事务管理器 管理的Session,此时应配置:

hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext。

另外在hibernate中使用 sessionFactory.getCurrentSession()获取session时,需要为方法声明事务,为此将sqlserver。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10015548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存