This content has been marked as final.
Show 1 reply
-
1. Re: Update a Session in a different thread
mkouba Nov 18, 2014 5:07 AM (in response to ge0ffrey)Hi Geoffrey,
you can't because the session context is only active during the service(), doFilter() and listeners notifications. I think you should really use the centralized location to store the results (as John Ament suggested), possibly an application scoped bean. As to the session timeout - you could simply implement a HttpSessionListener.sessionDestroyed(HttpSessionEvent) and remove all the results if necessary. I'm not sure about stopping a running task (this would require some further synchronization), but discarding the results would be simple.
- use JAX-RS @Context HttpServletRequest to inject the current request (this must be supported on all servlet containers)
- invoke HttpServletRequest.getSession(true) to be sure a new session is created if necessary
- take the session id (HttpSession.getId()) and:
- initialize the entry in the centralized store
- pass this id to the SolverCallable
- implement HttpSessionListener.sessionDestroyed() and remove the entry from the centralized store if necessary (timeout, logout, etc.)
- at the end of the computation, check whether there is a relevant entry in the centralized store, if not, discard the result