This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes single-threaded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "single-threaded" Watch "single-threaded" New topic
Author

single-threaded

tony kanvas
Ranch Hand

Joined: Oct 26, 2002
Posts: 97
A servlet can be made thread safe by running it in the single-threaded model.
isnt this statment true ??
Mike J. Beaty
Greenhorn

Joined: May 16, 2003
Posts: 9
To be exact you implement the SingleThreadModel. This is not always thread safe. If you have declared static class variables only one copy of these will be available for all of the threads. Also, any use of session or context attributes will not be thread safe either. You could synchronize the block of code that access these but you would be taking a huge performace hit if there were any significant amount of users.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Doesn't the SingleThreadModel mean that the servlet container will never create more than one thread for this servlet?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
John Pickler
Greenhorn

Joined: Jul 03, 2003
Posts: 2
Correct, but as one exam software I use pointed out, that doesn't prevent your "single threaded" Servlet from launching its own threads. Those threads could then make your single Servlet instance not "thread safe". The bottom line for the exam is that implementing the SingleThreadedModel interface definitely does not guarantee your Servlet to be thread-safe.
Ken Januski
Ranch Hand

Joined: Aug 08, 2002
Posts: 130
I believe that it guarantees one thread per servlet instance but containers can pool instances of the servlet class.
tony kanvas
Ranch Hand

Joined: Oct 26, 2002
Posts: 97
I think it will depends attribute scopes that used , like if we use local var it will be thread safe
Instance var will not ,and class var (static) will not too .
I think the question a above missing to clarify the attribute scopes type.
am i right?
Ken Januski
Ranch Hand

Joined: Aug 08, 2002
Posts: 130
I think the question probably, and I can only say probably, is to make you realize that implementing SingleThreadModel doesn't in and of itself guarantee thread safety. There are a number of gotchas that need to be kept in mind when using it. The Deshmukh book says one reason not to use it is:
"a false sense of thread safety."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: single-threaded