Search code examples
jspglassfishmemory-managementjspincludejsp-fragments

Including lots of jspf files in a jsp file causes high memory usage


We have a web page, running on a glassfish server. In our jsp file we have a lot of includes like the one below.

<jsp:directive.include file="johndoe/foobar.jspf"/>

These files are included according to the user choice. Our jsp file is basically like this:

<jsp:root version="2.1" xmlns:c="http://java.sun.com/jstl/core_rt"
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:jsp="http://java.sun.com/JSP/Page" 
xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
//some unimportant codes here
<c:if test="${sessionScope.loadAvgTest}">
  //some unimportant codes here
  <f:subview id="reports15">
    <jsp:directive.include file="siforms/sysinfoform.jspf"/>
  </f:subview>
  //some unimportant codes here                                        
  <f:subview id="reports16">
    <jsp:directive.include file="siforms/sysinfoformscheduled.jspf"/>
  </f:subview>
   //some unimportant codes here
</c:if>
//some unimportant codes here
<c:if test="${sessionScope.bandwidthTest}">
  //some unimportant codes here
  <f:subview id="reports17">
    <jsp:directive.include file="mailforms/mailfilter.jspf"/>
  </f:subview>
  //some unimportant codes here
  <f:subview id="reports18">
    <jsp:directive.include file="mailforms/mailfilterscheduled.jspf"/>
  </f:subview>
//some unimportant codes here
</c:if>
....

There are approximately 80 if statements like this each one containing 2 inculdes. When I removed a lot of these if clauses and leaved only a few if and a few include memory usage was fine. But as I use more if clauses and more includes the memory usage grows. Any ideas how I can optimize the code or how I can make configuration changes to the servlets configuration to lower the memory usage?


Solution

  • Using jsp:include instead of jsp:directive.include solved the problem. As far as I have learned from my research jsp:directive.include (include directive) includes the file into the JSP page at compile time whereas jsp:include includes the output at runtime.

    I have found that, include action (runtime include) runs a bit slower 
    yet it is preferred generally because it save a lot of memory of the system. 
    

    (source)