Reputation: 33
I have a Struts2 application that has an action that can take anywhere between 1 sec to 5 mins to run. So, I'm using the execAndWait interceptor to display a wait page if the action takes more than 20 secs to run. The setup of the action looks like this:
<action name="myAction" class="myActionClass">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="execAndWait">
<param name="delay">20000</param>
</interceptor-ref>
<result name="success">myPage.jsp</result>
<result name="wait">waitPage.jsp</result>
</action>
I have tested this with a scenario where the action just takes 1 second to run. I expected that the wait page will never be shown.
However, the wait page still showed up. I tried debugging my action class and method and found that the execution hangs at this statement below for the time specified in the
<param name="delay">
In this case, it waits for 20 secs at the statement below and then completes execution successfully.
getSession().put(A_SESSION_VARIABLE, 10);
Note: MyActionClass does implement SessionAware
Has anyone else experienced this problem? Is there a work around for this?
Upvotes: 2
Views: 1152
Reputation: 24396
A workaround (if your action is used in a servlet environment): implement ServletRequestAware
interface and use HttpServletRequest
to get session.
request.getSession().setAttribute(A_SESSION_VARIABLE, 10);
Upvotes: 2
Reputation: 3168
I have a different approach for this problem. You can run the heavy processing in a separate thread and return the response to the user instantly stating that the work is in progress. When the work is finished you can return whatever you want to return to the user. This can be achieved by using polling.
In the meantime user don't have to wait and can do other stuff.
Hope it helps.
Upvotes: 0