I have a Struts 2 application deployed on Tomcat 6. I am facing an issue with a form which has a text field and a button. The button click action persists some data to the database.
I came across a problem today when I am invoking the action(button click) multiple times.
For e.g: Clicking the button 5-6 times. This causes my application to hang and I am not able to navigate to any other page in the application. Even re-starting the browser does help and my application gets into a some kind of a never ending deadlock ..
When I stop the tomcat server I get the following log messages on tomcat console:
After re-starting the server the application starts fine but the same problem reoccurs when I do the same action again (hitting the button 5-6 times).
Guys please help me to get rid of this issue.
I initially suspected the my database logic was causing some problem. So get rid of all db code and just did the following steps:
1. Created a form in the application with just one text field and a button
2. The action of the button was to hit some java code and print a success message on the jsp. (No db logic here)
3. When I hit the button more than 5-6 times my application hangs again.
I wouldn't say that Tomcat is causing the application to hang. More likely that the application itself is making the application hang.
Do you by any chance have any member (instance) variables in the action processor class? I've seen people do this. Or for that matter, are there class variables?
The problem is that Struts action processors are not thread-unique. Or, more plainly, only one instance of the action processor is created, and when you send multiple requests to it, whether from multiple users or simply one twitchy user who hits the submit button faster than the processor can run to completion, there's a possibility that one thread can muck up the state of the object for another thread, with unpredictable results.
An IDE is no substitute for an Intelligent Developer.
Joined: Apr 05, 2011
I solved the problem after spending 2.5 days on it.
This was something to do with the usage of MyBatis FMK in my application. Basically happenned due to multiple people working on the code ..
In MyBatis we used a logic were we had opened SqlSession () but somehow forgot to close the session and hence the issue ...
The other parts of the application had used the session object correctly by instantiating the object via dependency injection. By doing this we don't need to open and close session explicity. The fmk takes care of it.
And on the better part of 2.5 days I looked into the code which was using the object correctly .. .