Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic