Tuesday, May 13, 2008

Servlets and Garbage Collection

Basic Cycle
  1. The destroy() method is called by the servlet container when the container decides to unload the servlet instance itself.
  2. After the destroy() method completes, the servlet engine unloads the servlet,.
  3. Then, the JVM eventually performs garbage collection on the memory resources associated with that servlet object.
Effecient Servlet : Goals

When can you say that a Servlet is efficient , well of course when it does your work in most effecient manner or in other words the algorithm/logic that you have in it is effecient... but there's more to its efficiency .. Read On !!

Secondly even for High volume Web applications, one needs to carefully control the amount of garbage created during page generation. More the garbage created, fewer the pages generated, and the slower is the response time for a particular request. ( This bottleneck occurs because the Java VM has to steal cycles to run garbage collection when it should be generating pages. ) On the flip side , if too much garbage is created, request processing could halt entirely. Which is unacceptable.


Third is to keep the browser active: not too much of "waiting for response" messages. To put it in programatic terms the time a bean spends querying backend is the time a user spends waiting for page to display. This can -- and should -- be avoided using servlet response streaming techniques.

No comments: