|
INTERVIEW QUESTIONS
J2EE
SERVLET
DETAILS
Question: What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
Answer: Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data.
The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading. Also, note that SingleThreadModel is pretty resource intensive from the server's perspective.
The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free - which results in poor performance. Since the usage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool.
|
|
|
Category |
Servlet Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7945 users |
Added on |
10/25/2009 |
Views |
78825 |
Rate it! |
|
|
Question:
What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
Answer:
Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data.
The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading. Also, note that SingleThreadModel is pretty resource intensive from the server's perspective.
The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free - which results in poor performance. Since the usage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool. Source: CoolInterview.com
If there is instance variable in Servlet, use ThreadLocal and put this variable in ThreadLocal's map. Source: CoolInterview.com
Answered by: Vaibhav | Date: 3/7/2010
| Contact Vaibhav
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
If you want a servlet to take the same action for both GET and POST request, what should you do?
|
View Answer
|
|
What is the servlet life cycle?
|
View Answer
|
|
Which code line must be set before any of the lines that use the PrintWriter?
|
View Answer
|
|
How HTTP Servlet handles client requests?
|
View Answer
|
|
What is the Servlet Interface?
|
View Answer
|
|
When a servlet accepts a call from a client, it receives two objects. What are they?
|
View Answer
|
|
What information that the ServletRequest interface allows the servlet access to?
|
View Answer
|
|
What information that the ServletResponse interface gives the servlet methods for replying to the client?
|
View Answer
|
|
What is the servlet?
|
View Answer
|
|
What are the uses of Servlets?
|
View Answer
|
|
What are the advantages using servlets than using CGI?
|
View Answer
|
|
What is the difference between servlets and applets?
|
View Answer
|
|
Difference between single thread and multi thread model serv
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Servlet Interview Questions & Answers - Exam Mode /
Learning Mode
|