本文介绍了JPA事务的超时实现和会话无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我一直在处理使用 wicket + JPA + springs 技术的应用程序.最近我们在日志中遇到了许多5XX错误(大于阈值).由于 大型机db2 的响应时间不稳定而存在一些一般性问题,对于我们的应用程序来说,该响应时间为 后端 .但是在大型机正常之后,该应用程序服务器就不再恢复正常.

I have been handling a application which uses wicket+JPA+springs technologies.Recently we got many 5XX error in logs(greater than threshhold).During that time,There were some general problems due to unstable response times of the mainframe db2 which is backend for our application.But after that once the mainframe is OK this application servers did not come to normal again.

(根据我的应用程序)有很多挂起的交易.服务器中可能有许多挂起的线程.在此期间,由于用户继续保持登录状态或将以重复方式访问链接,因此情况变得更糟.

There are a lot of hanging transactions (from my appplication).There are many threads in the server that may be hung.As users will go on keeping login or will access the links in aplication during that time the situation becomes worse.

当我查看webspehere日志时,发现以下异常:

When I look at webspehere logs I found following exceptions:

00000035 ThreadMonitor W WSVR0605W: Thread "WebContainer : 88" (000005ac)
has been active for 637111 milliseconds and may be hung.
There is/are 43 thread(s) in total in the server that may be hung.

在应用程序日志中,我发现以下异常:

In application logs i found following exceptions:

-->CouldNotLockPageException: Could not lock page 4. Attempt lasted 3 minutes
-->DefaultExceptionMapper - Connection lost, give up responding.
   org.apache.wicket.protocol.http.servlet.ResponseIOException:
   com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encountered error during
   write.
--> JDBCExceptionReporter - [jcc][t4][2030][11211][3.67.27] A communication error occurred
   during operations on the connection's underlying socket, socket input stream,
   or socket output stream.
   Error location: Reply.fill() - socketInputStream.read (-1).  Message:
   Connection reset. ERRORCODE=-4499, SQLSTATE=08001DSRA0010E: SQL State = 08001, Error Code = -       4.499

现在我们正在研究此问题的解决方案.以下是我们目前正在考虑的两个解决方案.

Now we are working on the solutions to this problem.The follwing are two solutions that we are thinking as of now.

1.我浏览了很多论坛,发现每当我们收到CouldNotLockPageException时,最好入侵会话并强迫用户登录页面,目前我们没有会话失效(登出)机制,因此我们将实现那一个.

1.I have gone through many forums and found that whenever we get CouldNotLockPageException then it would be better to invaidate the session and force user to login page.Currently We do not have session invalidation (logout) mechanism.So we will implement that one.

2. 我们需要实现交易超时,以便我们停止挂起交易.

我需要从Java或服务器端解决此问题.这里我们使用的是 wicket,jpa和springs框架 .我的查询很少.

I need solution for this problem from java or server side.Here we are using wicket,jpa and springs frameworks.I have few queries.

1.如何在上述框架中实现交易超时?

2.无效会话是否可以停止挂起事务或可能挂起的线程?

推荐答案

由于您已经在使用Spring,就这么简单:

Since you are already using Spring, it's as simple as that:

@Transactional(timeout = 300)

事务注释允许您提供超时值(以秒为单位),事务管理器会将其转发到JTA事务管理器或数据源连接池.它可以与Bitronix Transaction Manager配合使用,后者会自动将其提取.

The Transaction annotation allow you to supply a timeout value(in seconds) and the transaction manager will forward it to the JTA transaction manager or your Data Source connection pool. It works nice with Bitronix Transaction Manager, which automatically picks it up.

您还需要确保java.sql.Conenction始终处于关闭状态,并且Transaction始终会被提交(当所有操作成功时)或在失败时回滚.

You also need to make sure the java.sql.Conenction are always being closed and Transaction are always committed (when all operations succeeded) or rollbacked on failure.

使用户http会话无效与jdbc连接无关.您的jdbc连接应始终被提交/回滚并关闭(在连接池的情况下,将释放到池的连接).

Invalidating the user http session has nothing to do with jdbc connections. Your jdbc connection should always be committed/rollbacked and closed(which in case on connection pooling, will release the connection to the pool).

并确保最大池大小不大于tour db max并发连接设置.

And make sure the max pool size is not greater than tour db max concurrent connections setting.

这篇关于JPA事务的超时实现和会话无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:13