Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What happens in Servlet context object  RSS feed

 
surendar prabu
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me about the reference of servlet context object.

I have a class MyClass. This object is set to servlet context.
ServletContext.setAttribute("MyClass",MyClass);
Later in some other request class i have
protected void doGet(HTTPREQ,HTTPRES)
{
myClass = (MyClass)ServletContext.getAttribute("Myclass");
}

What happens here when multiple requests come? Will each request have their own instance of MyClass or they all refer to the same instance in servlet context.

request 1 says myClass.myvar = 10;
request 2 says myClass.myvar = 20;

What value is available for these two requests finally??

Help me on this. I have tried requesting from multiple clients. yet i could not figure out.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The object exists only once. So from the time you set that field to 10, all accesses will get 10, until you set it to 20, at which point each access will get 20.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!