wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Another Mock Exam Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Another Mock Exam Question" Watch "Another Mock Exam Question" New topic
Author

Another Mock Exam Question

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Which is the better approach for enabling thread safe servlets - single thread model or synchronization?
a. Depends on the level of user access.
b. Both are equally good.
c. Depends on the number of hits on the site.
Which one is the correct answer?
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=18&t=000663
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
I think answer is C, Depends on the number of hits on the site.
IF you have verfy high number of hits and you implement single thread model, the container will queue all the request to a single instance or create multiple instances. This will be very slow.
If you do not implement SingleThread model, you can have multiple threads running and you can synchronize access to shared resources.
A. I do not understand this option
B. Both are not equally good. As I explained above implementing SingleThreadModel makes things slower and synchronizing may create bottleneck.
C. I think this is the answer.
I would love to see more comments.
Chintan


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
g madhava
Ranch Hand

Joined: Sep 14, 2001
Posts: 85
Which is the better approach for enabling thread safe servlets - single thread model or synchronization?
Depends on the level of user access.
Both are equally good.
Depends on the number of hits on the site.

User access has nothing to do with thread safe servlets and also with the single thread model.User access depends on authentication and authorization.And both the tasks are independent of thread synchronization with in the context given above.
Single Thread model could be used where in the number of hits are less.
while synchronized code block if used correctly could be used for a site which has high number of hits.
So the answer is (C)
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
Chintan and Madhava, although the answer is C but your explanations are totally opposite to what the posts I refered above, convey.
If a site has a lot of users, you should use SingleThreadModel and not make your methods synchronized. You might want to read those posts again.
Jim Bertorelli
Ranch Hand

Joined: Nov 28, 2001
Posts: 136
Actually this question doesn't make sense. It depends on how the servlet is coded or what the servlet can or cannot do. For example, if a servlet uses class variables for sharing, you cannot use STM but if it only uses instance variable, STM will be more efficient than synch. methods. In any case, nobody thinks of using a less efficient approach even if the number of users is less!!!
Where did you get this question???
[ January 11, 2002: Message edited by: Jim Bertorelli ]
g madhava
Ranch Hand

Joined: Sep 14, 2001
Posts: 85
Hi Jim,
Contrary to what was being discussed in that particular thread,IBM says not to use SingleThreadModel.
Take a look at this document:
http://www-4.ibm.com/software/webservers/appserv/ws_bestpractices.pdf

NOTE: The main assumption in using the Java technology for server side applications is that the time taken for the network connections between the client and the server is more than the time taken for processing at the server.
thanks,
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
What the document says is indeed correct. However, it does not compare SingleThreadModel with synchronized doXXX methods approach, which is what the question (and the referred thread) is talking about.
Of course, both the styles should be avoided due to performance issues and it is almost always better to code the servlet in a thread safe manner rather than resorting to these "brute force" technique.
HTH,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
i think the correct answer is c.
if there is a choice d) in which if it would be given that sysnchronization is best.It would be close because if u have synchronized properly where needed because after that u arn't woory about the no of user because in SINGLETHREAD MODEL (may server has not done good implementation and has done synchronized the doxxx method.)
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
i think the correct answer is c.
if there is a choice d) in which if it would be given that sysnchronization is best.It would be close because if u have synchronized properly where needed because after that u arn't woory about the no of user because in SINGLETHREAD MODEL (may server has not done good implementation and has done synchronized the doxxx method.)
g madhava
Ranch Hand

Joined: Sep 14, 2001
Posts: 85
Hey Paul,
Come on,you got to be kidding.What is the other way in servlets,you would be handling the Synchronization issue without using the
SingleThreadModel interface ??
thanks,
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
synchronizing the doXXX methods?
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

I would also go for C. But today's Jason Hunters would ofcourse prefer not to use SingleThreadModel in a performance-critical solution and go for synchronizing specific methods, bolcks themselves....


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
 
Consider Paul's rocket mass heater.
 
subject: Another Mock Exam Question
 
Similar Threads
A Real Bear of a Problem
Thread.yield() method - where do we call it
RMI server
Thread
another thread doubt