Sunday, August 21, 2005

JSP Performance Tips

Here are a few tips to improve JSP performance that I have been using. If you have your own listing of the tips, plz share.

  • Disable JSP auto reloading feature.
  • Use thread pool for your JSP engine and define the size of thread pool as per application requirement.
  • Use jspInit() method to cache static data
  • Initialize the 'out' object (implicit object) with proper size in the page directive.
  • Set the content length
  • Give 'false' value to the session in the page directive to avoid session object creation.
  • Flush the data partly
  • Use StringBuffer rather than using + operator when you concatenate multiple strings
  • Use include directive instead of include action when you want to include the child page content in the translation phase.
  • Avoid giving unnecessary scope in the 'useBean' action.
  • Use print() method rather than println() method
  • Use ServletOutputStream instead of JSPWriter to send binary data
  • Minimize code in the synchronized block
  • Do not use custom tags if you do not have reusability.
  • Use 'session' and 'application' as cache.
  • Remove 'session' objects explicitly in your program whenever you finish the task
  • Use caching tags provided by different organizations like openSymphony.com
  • Reduce session time out value as much as possible
  • Release resources in jspDestroy() method.
        • 3 comments:

          Anonymous said...

          All of these tips are good. However, these seem low-level, as if you are manually writing the JSP-to-Servlet conversion. Are you?

          Rajneesh Garg said...

          Not really. I am not referring to 'manual JSP-to-Servlet' conversion. r u referring to tips related to jspInit and jspDestroy methods?

          Anonymous said...

          Use JSP comments over HTML comments.
          See http://www.karstenvoges.de/blog/archives/2004/06/17/howto_comments_in_jsps.html

          Total Pageviews

          Reading List - 05-Mar-23

          Talking to #AI may be the most important job skill of this century ( JohnGoodPasture ) Role of account management over the years. It’s a ro...