• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher and thread-safe

 
Satheesh Satti
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Can some one please answer the following question.
Is the RequestDispatcher returned by getRequestDispatcher(java.lang.String path) of ServletContext class thread-safe.

Thanks
Satheesh.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you declare it in (and keep it local to) the service method (doPost, doGet...) it is.

If you declare it as an instance variable and set it's value in the service method, no.
 
Satheesh Satti
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many Thanks for ur reply.

It is an instance variable and it is being set once in the init method of the servlet which will be called only once when the servlet is loaded and later on I am using it to do the forwards in the service methods(doGet etc..,).Is it safe to do something like that.

Thanks again,
Satheesh.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely not. Re-read Ben's reply.
[ September 12, 2005: Message edited by: Bear Bibeault ]
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What make you think that request dispatcher returns every time a new instance instead of reusing one?
 
Satheesh Satti
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the responses

I am wondering what spec says about it and API doesn�t say that RequestDispatcher returned by servletContext is not Thread Safe. I am using Tomcat and hence can know whether I can do it or not by looking in to the RequestDispatcher implementation. But that makes my code vendor specific and didn�t want to do something like it.

I am using at as read only inside the Service Methods by assigning it once in the init Method.

Thanks,
Satheesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic