Also can we make forward()calls in a loop..
RequestDispatcher rd = new RequestDispatcher(/servlet/ServletB);
Can anyone please rep.
Thanks and Regards,
why don't you use a thread in servletA to invoke the method rd.forward(request,response). Have servlet A implement Runnable
Then in servlet A:
This will generate 100 threads each invoking the forward method.
I am not sure whether you want the same request object to be sent in each forward call in the loop or not. I assume that you want to send the same request object that (you recieve in the doGet or doPost method) as argument in each forward call of the loop. However I also assume that for each such call only the attribute 'A' of the request will differ. So I obtain a clone of the request object sent for that doGet or doPost and simple add/modify the 'A' attribute before passing it thru the forward method.
If you don't like the cloning method another way is to put the
inside the run method and start a thread :<br>
hope this helps
Thnaks for the suggestion.
But there seems to be a problem. You had suggested a clone() of HttpServetRequest. But when we do it we get a compilation error that clone() is a protected method in java.lang.object
we are not sure of this clone() ka funda. Can u throw some more light into ur logic??
Thanks and Regards,
Originally posted by Ganapathi Raman:
We want to give the request and response objects from one servlet (say Servlet A) to another (say Servlet B). But we do not want Servlet A to wait until Servlet B finishes this request. We want to Servlet A to dispatch this info to Servlet B and continue with its own processing [...]
There seems to be something fundamentally wrong about what you're trying to do. HTTP Servlets are objects which generate HTTP responses in response to HTTP requests, or delegate the generation of such responses.
If there is some work which should be done after forwarding the request to bean B, this work has no part in generating the response. For that reason alone it does not belong in a servlet, but in an ordinary Java class. Why not create a Runnable class C which implements this work? Immediately before the forward, you could say new Thread(new C()).run() to kick off the background work (probably not exactly this, but you get my drift).
If servlet A gets a lot of load, consider using an application-bound thread pool consuming Runnable jobs from a job queue.