wood burning stoves 2.0*
The moose likes JSP and the fly likes Improving JSP Performance by using StringBuffer & writing it to the Output Stream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Improving JSP Performance by using StringBuffer & writing it to the Output Stream" Watch "Improving JSP Performance by using StringBuffer & writing it to the Output Stream" New topic
Author

Improving JSP Performance by using StringBuffer & writing it to the Output Stream

Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
In our Application, there is a very complex HTML page to be rendered. The JSP sends out 13000 odd lines of HTML to the browser. There is lots of Java looping involved in the JSP. We found from our logs that the JSP takes approximately 40 secs to finish execution. The App is running in our Client's Intranet. We have access to that intranet and the link is pretty fast.

Instead of generating the HTML in loops, I appended a good chunk of the HTML in a StringBufer object and sent it to to the Browser in one go by <%=objStringBuffer.toString()%>. But the page now took more time to my dismay.

Is there any workaround ?

Cheers,
Arvind
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The comment I'm about to make is not really a JSP issue and you may want to take it to the perfomance thread...

StringBuffer, if not used properly can actually be more expensive than string concatenation. According to "Harcore Java" (can't remember the author's name), if you use the concatenation operator inside the argument params to the append method, a new StringBuffer object has to be created.

Example:


Accourding to this book, it is much more efficient to make a separate call to the append method for every addition to the buffer.



Hope it helps.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
if you use the concatenation operator inside the argument params to the append method, a new StringBuffer object has to be created


There are quite a few concatenations inside the call to append(). The UI is complex. To add on it, there is lots of DHTML stuff and lots of dynamicity at JSP level.

Refactoring the entire JSP such that there is no concatenation inside append() is not just possible

Guess, am Screwed

Anyway Cheers,
Arvind
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Improving JSP Performance by using StringBuffer & writing it to the Output Stream