Alex Rivera | Logout

How to clone a detached HttpServletRequest and HttpServletResponse provided by the Servlet Container?

Asked 2011-03-11T13:36:59.037
9

I want to implement the following logic: when I receive HttpServletRequeset and HttpServletResponse in main servlet's doService method (in the main web Container thread),I start A,B,C three threads (thread managed by my own program) to process other servlet in parallel mode,and then join each response from these servlet in main thread,and if one of my own thread (assume A thread) work slow,the main thread will finish,so main response will return to user.and the A thread must continue work properly,I will request the response of the A thread using AJAX in browser side later.

So,I want to clone the HttpServlettRequest and HttpServletResponse provided by the Servlet Container,and the cloned request and response must be detached(When container's HttpServletTrequest and HttpServletResponse finished,the cloned request and reponse still work properly).

The behave of the cloned request and response must be same as the Container's from my code's view.It can be followed and included.

Any idea?

Thanks very much!

L.J.W

Edit
Report

1 Answer

3

The request and response classes aren't designed to be cloned or accessed from multiple threads. If you try to do so, you're bound to run into problems. I suggest that you re-think your requirements.

answered 2011-03-11T14:37:12.100

Your Answer