• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pls make me clear

 
Venkat Perumalla
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFJ page# 192 it says that context attributes are not thread safe and to make them thread safe we have to use synchronized methods, but in page 313 which says for a JSP its default thread safe, whcih means it cannot have multiple threads access at a single time, but the explanation there was little different

Pls correct me if i am wrong and also make me clear on thread safe concept,

Thanks in Advance !!!
[ September 23, 2006: Message edited by: Venkat Perumalla ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that this has more to do with the SingleThreadModel. If you specify the isThreadSafe value to be false then, this servlet ( JSP ) will implement the SingleThreadModel ( which is evil ! ). So you need to synchronize with the ServletContext anyway.
 
Venkat Perumalla
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey John can you please make me more clear,If isThreadSafe value is set to true which means it is thread safe and was implementing singlethread model, So therefore single thread can access it at a time.

Am i correct!
[ September 23, 2006: Message edited by: Venkat Perumalla ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it means that only one client is serviced at a time by the service method. But that wont prevent another JSP file from accessing this servletContext and changing the attribute that you are working on. So you have to use a synchronized servletContext anyway. isThreadSafe is true by default and you still have to write extra code to make sure that code is thread safe.
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the book was right.The context parametes are not thread safe.Context parameters are shared between all the servlets.But the page attributes (page context) are only available to the page.If you look at the generated code for servlet to a jsp page you would see something like that.

PageContext page = new PageContext();
This mean the page context attributes are local to the _jspService method.
Which means one thread can access this method at the same time.
[ September 23, 2006: Message edited by: Khaled Mahmoud ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic