This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Urgent

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ganapathi Srinivasan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic