Timeout implementation of JPA transactions and Session invalidation

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.

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.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.We need to implement transaction timeouts so that we can stop hanging transactions.

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.How can we implement transaction timeouts in the above frameworks?

2.Will invalidating session can stop hanging transaction or threads that may hung?

Answer

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

@Transactional(timeout = 300)

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.

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.

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).

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

Leave a Reply

Your email address will not be published. Required fields are marked *