• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronizing getAttributes() method  RSS feed

 
mukesh chandan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...

why there is a need to synchronise servlet context methods like getAttributes() method..

thanks all...
 
bhavesh bhatnagar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why there is a need to synchronise servlet context methods like getAttributes() method..


We Synchronizes to ensure that ServletContext is Thread Safe

You either synchronizes the Service method(doGet()/doPost()) or creates the synchronized block.
[The first option prevents Concurrency.]

in second method we do something like

synchronized(getServletContext())
{
//Methods of ServletContext
}


we dont synchronized any perticular method.. but ServletContext Object. in order to make Thread Safe.

By Thread Safe we mean::

there was multiple servlets and multiple threads as well..
but context object is common to all..
so if some thread sets some values and before it gets it.. some one else changes it(or set its value)..


 
mukesh chandan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bhavesh...
i got it alright...




 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!