Menu

Session already invalidated

2015-06-13
2015-06-19
  • Rommel V. Lagera

    I have a long duration process inside an action which may exceed 30 minutes (default Tomcat idle timeout). In the future this may even reach an hour of processing.

    How can I properly prevent a "Session already invalidated" error in this particular action without affecting other modules/actions? Other modules/actions should stay at default timeout.

     
  • Javier Paniza

    Javier Paniza - 2015-06-15

    Hi Rommel:

    For a long process I would create a new thread, so the action will terminate instantly. Afterwards, you can have other part of the application to check the status of your process.


    Help others in this forum as I help you.

     
  • Rommel V. Lagera

    Hi Javier,

    I have not tried your solution yet, but I would like to ask will the thread process not be affected by session timeout. My deployment is inside Liferay and it seems to stop any process after session timeout.

    Thanks,

    Rommel

     
  • Trifon (An ADempiere founder)

    Hi Rommel,

    I have not tested it, but in your OpenXava action you can take current Http Session and invoke method:

    HttpSession.setMaxInactiveInterval(int seconds)

    Please test it and let us know if it works for you.

    Kind regards,
    Trifon

     
  • Rommel V. Lagera

    Hi Trifon,

    I've used getRequest().getSession().setMaxInactiveInterval(-1) inside the action to temporarily disable session timeout.

    But I got a different error in dwr (no more Session already invalidated), now it is java.lang.NullPointerException at org.openxava.web.dwr.Module.getview(Module.java:494).

    Do I have to set it (MaxInactiveInterval) somewhere else other than inside the action itself?

    I am using OpenXava 5.2.1.

    Regards,

    Rommel

     
  • Javier Paniza

    Javier Paniza - 2015-06-17

    Hi Rommel,

    Try the thread solution, it should survive the session. However, you should not use session state from your thread.

    Other option is to use Quartz and planing a job to start just a seconds after your action.


    Help others in this forum as I help you.

     
  • Laurent Wibaux

    Laurent Wibaux - 2015-06-19

    Hi Rommel,

    One clean and simple way to do long processes is to use Threads started and stopped by a ServletContextListener:
    1/ Create your Thread implementing Runnable: this thread will look for a flag set by your action in a table and run at that time. It can look at the flag every minute and sleep the rest of the time. This could also ensure that another user does not start the long action when it is already running.
    2/ Create your listener implementing ServletContextListener to start your Thread when the server is started.
    3/ Add your listener class to listeners.xml in web/WEB-INF

    I use this approach for many background processes in my Liferay/OpenXava 5.2.1 (retrieving currency rates and storing them in a table, updating prices, importing and exporting data through flat files from various IT systems) and it works very well.

    Regards,

     

Log in to post a comment.