Note, there's only actually one PerThread service here which is
RequestGlobals.
All other services (Request, Response, ApplicationStateManager) point to
this service. So, if you initialize RequestGlobals your async worker should
be OK.

You might be able to do the Following.

public class SomePage {
   @Inject RequestGlobals requestGlobals;
   @Inject PerThreadManager perThreadManager;

   void onSomeAction() {
      final HTTPServletRequest realHttpRequest =
requestGlobals.getHTTPServletRequest();
      final HTTPServletResponse realHttpResponse =
requestGlobals.getHTTPServletResponse();
      final Request realRequest = requestGlobals.getRequest();
      final Response realResponse = requestGlobals.getResponse();

      Runnable worker = new Runnable() {
         public void run() {
    try {
   requestGlobals.storeServletRequestResponse(realHttpRequest,
realHttpResponse);
   requestGlobals.storeRequestResponse(realRequest, realResponse);

   doStuff();
} finally {
   perThreadManager.cleanupThread();
}
         }
      };

  Future<?> future = myExecutor.submit(worker);
  ...
   }
}

Reply via email to