Hibernate需要每天重启一道的奇怪问题,请大虾指点!

SoulOfEdge 2005-12-30 08:39:38
我有一个Web程序,每次运行之后都很正常,但是一到第二天早上再来登陆的时候,就报错,说连接已经关闭。需要重启,但是只能管一天!
No operations allowed after connection closed. Connection was closed due to the following exception: ** BEGIN NESTED EXCEPTION ** java.sql.SQLException MESSAGE: Communication link failure: java.net.SocketException, underlying cause: Software caused connection abort: recv failed ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Software caused connection abort: recv failed STACKTRACE: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at…………
………………

引起错误的代码如下:
public UserInfo authenticate() throws Exception {
try {
Session session = HibernateUtil.currentSession();
session.beginTransaction();
Query q = session.createQuery("select u from u in class UserInfo where u.email=:email and u.password=:password");
q.setParameter("email", getEmail());
q.setParameter("password", getPassword());
List result = q.list();
if (!result.isEmpty()) {
return (UserInfo)result.iterator().next();
}
else {
ValidationDelegate delegate = (ValidationDelegate) getBeans().getBean("delegate");
delegate.setFormComponent(null);
delegate.record("Login failed, wrong username or password", null);

}
session.beginTransaction().commit();
} catch (HibernateException e) {
HibernateUtil.currentSession().beginTransaction().rollback();
e.printStackTrace();
} finally {
if (HibernateUtil.currentSession() != null)
try {
HibernateUtil.currentSession().flush();
HibernateUtil.closeSession();
} catch (Exception e) {
e.printStackTrace();
}
}

return null;
}
...全文
277 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
steiven 2006-01-01
  • 打赏
  • 举报
回复
是的,这是连接池的问题,换成容器自己的连接池会好的,这是因为mysql在连接timeout的时候会断开,而连接池自身如果不能自动判断和重新连接就会出问题的。
SoulOfEdge 2005-12-31
  • 打赏
  • 举报
回复
娃哈哈哈哈,经过一夜的等待,俺的程序终于不用重启了^_^
果然是连接池的问题,8小时……各位大虾的支持不胜感激,解贴!
mxlmwl 2005-12-30
  • 打赏
  • 举报
回复
pigo(p) ( ) 信誉:130 说的很有道理,以前记得在哪里也曾见过的。另外,如果使用c3p0的话,也要注意连接池的配置,不正确的配置仍然会让你系统变的很慢,甚至web容器没有响应。这些我都领教过的。
SoulOfEdge 2005-12-30
  • 打赏
  • 举报
回复
谢谢楼上各位兄弟支持,小弟用的正是Mysql数据库,正在揣摩中……
pigo 2005-12-30
  • 打赏
  • 举报
回复


数据库是mysql吧???

这个是mysql的8小时问题,
超过8小时没任何操作的连接被服务器端强制断开连接,
而此时连接池中认为该连接还是有效的。

解决办法参考下面这篇blog:

http://bjzhanghao.cnblogs.com/archive/2004/12/10/75145.html


奇伢 2005-12-30
  • 打赏
  • 举报
回复
楼上的那位说的有一定根据的,分析日志的时候我也发现有roll back失败的问题。

楼主用什么数据库?
wmzsl 2005-12-30
  • 打赏
  • 举报
回复
我没有测试,不过大概就是那么写,你自己测试一下就行了
奇伢 2005-12-30
  • 打赏
  • 举报
回复
mark
我前两天也遇到这种情况,狂郁闷。。。
现在我该了下连接池的配置,正在测试。。。。好像这两天还没有出问题
wmzsl 2005-12-30
  • 打赏
  • 举报
回复
是你的事务处理的有问题!修改你的事务处理!

public UserInfo authenticate() throws Exception {
Transaction t = null;
try {
Session session = HibernateUtil.currentSession();
t = session.beginTransaction();
Query q = session.createQuery("select u from u in class UserInfo where u.email=:email and u.password=:password");
q.setParameter("email", getEmail());
q.setParameter("password", getPassword());
List result = q.list();
if (!result.isEmpty()) {
return (UserInfo)result.iterator().next();
}
else {
ValidationDelegate delegate = (ValidationDelegate) getBeans().getBean("delegate");
delegate.setFormComponent(null);
delegate.record("Login failed, wrong username or password", null);

}
t.commit();
} catch (HibernateException e) {
t.rollback();
e.printStackTrace();
} finally {
if (HibernateUtil.currentSession() != null)
try {
HibernateUtil.currentSession().flush();
HibernateUtil.closeSession();
} catch (Exception e) {
e.printStackTrace();
}
}

return null;
}
奇伢 2005-12-30
  • 打赏
  • 举报
回复
不是吧,8小时问题。我的系统晚上就是很少有人用的,上班时间人才多。怪不得。。。
SoulOfEdge 2005-12-30
  • 打赏
  • 举报
回复
to楼上兄弟:
不太像,就是内网几个人用用而已,我想还是别的问题
xzy825 2005-12-30
  • 打赏
  • 举报
回复
是不是连接池资源耗尽啊?减少连接看看

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧