This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP service method synchronization

 
J J Wright
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun�s ePractive exam includes the following question:

Your organization has developed a new J2EE Invoicing system, and during load testing the system runs slow, but CPU and memory utilization remain low. To save time they embedded all the business logic into the JSPs as scriptlets.

What could be a cause of the problem?

A. You need to scale your application horizontally
B. You need to scale your application vertically
C. Servlet instances are getting locked for every request
D. You are dropping database connections
E. Your load balancer needs to be re-polarized

The answer they give is as follows (Reference - Servlet 2.4 spec)

Option C is correct because the default behavior for JSPs is for the service method to be synchronized in the resulting servlet

I�ve always been of the opinion that the default model for Servlets, including Servlets generated from JSPs, is a multithreaded one. This is borne out by the Servlet and JSP specs. The JSP spec has the following to say about the isThreadSafe page attribute:

Note: The Servlet 2.4 specification deprecates SingleThreadModel, which is the most common mechanism for JSP containers to implement isThreadSafe. Page authors are advised against using isThreadSafe, as the generated Servlet may contain deprecated code.

Indicates the level of thread safety implemented in the page. If false then the JSP container shall dispatch multiple outstanding client requests, one at a time, in the order they were received, to the page implementation for processing. If true then the JSP container may choose to dispatch multiple outstanding client requests to the page simultaneously.

Page authors using true must ensure that they properly synchronize access to the shared state of the page.

Default is true.

Note that even if the isThreadSafe attribute is false the JSP page author must ensure that accesses to any shared objects are properly synchronized. The objects may be shared in either the ServletContext or the HttpSession.

Am I missing something obvious here?
 
mc khan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are correct. I'd be interested to know the answer to.
 
giuseppe fanuzzi
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i answer 'C' because the others are surely incorrect!
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think 'C' is for surely incorrect since there is only one Servlet instance it runs under threads
 
J J Wright
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to contact Sun directly regarding this one. I'll update the thread accordingly when, or should that be 'if', I get any feedback.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic