• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multithreaded service()

 
Steven Lau
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if service() method of a typical servlet is multithreaded, which one of the following issues does not need to be address in the servlet's implementation?
Concurrent access to =>>shared resouces ?
local variables?static variables? instance variables?

thanks
[ April 01, 2002: Message edited by: Roland2k1 ]
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Access to shared resouces outside the servlet is a concern, even if you are implementing SingleThreadModel, because all that is guaranteed is that only one thread will execute the service() method at a time.
2. Local variables are as thread-safe as they can be, since each thread as its own "copy".
3. Static variables are not thread-safe, even if you implement SingleThreadModel, because the specs allow the container to create a pool of servlets.
4. Instance variables are not thread safe. Even though only one servlet instance (per servlet definition) services requests, concurrent requests will spawn threads that can access that servlet's instance variables.
You can check out more of the specs here. It's actually very readable and informative
-anthony
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roland2k1,
Your display name does not conform with the Javaranch naming policy. Please read this policy and change your display name if you wish to keep posting here. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic