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?
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
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)
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.
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 ]
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,
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.
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.)
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.)
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,
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....
Post by:autobot
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking