Forums Register Login

Urgent

+Pie Number of slices to send: Send
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 something like an asynchronous call? Is this possible with RequestDispatcher.forward() ???
Also can we make forward()calls in a loop..
eg.
RequestDispatcher rd = new RequestDispatcher(/servlet/ServletB);
for(int i=0;i<100;i++)
{
request.setAttribute("A",A[i]);
rd.forward(request,response);
}

Can anyone please rep.
Thanks and Regards,
Ganp.
+Pie Number of slices to send: Send
Hi
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
regards
Tanveer
+Pie Number of slices to send: Send
Hi Tanveer...
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,
Ganapathi
+Pie Number of slices to send: Send
 

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.
- Peter
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1559 times.
Similar Threads
Servlet Lifecycle Doubt?
How to get JSP URL in Servlet
contextScope attribute setting
RequestDispather
calling one servlet from another servlet in separate JVM's
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:12:12.