• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Another Mock Exam Question

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=18&t=000663
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
synchronizing the doXXX methods?
 
Ranch Hand
Posts: 2379
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic