I know that this is not supposed to happen in Java, but I have a memory leak with a servlet that I was wondering if somebody could tell me where my problem might be?
I have done everything I can think of and it still exsists.
The only thing I can think is that the page that is creates is set to refresh every 30 seconds, but I can not believe that I am the only one doing that....
Below is my code:
package com.tms.server.loadmaster.www;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.tms.common.remote.lib.data.Query;
import com.tms.common.lib.StringList;
import com.tms.common.remote.lib.data.DataFactory;
import com.tms.common.loadmaster.import com.tms.common.lib.data.TableDescriptor;
import com.tms.common.lib.Application;
/**
* <p>Title: FccBrokerLoadServlet</p>
* <p>Description: Web site listing of avaible broker loads</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Fremont Contract Carriers</p>
* @author not attributable
* @version 1.0
*/
public class FccBrokerLoadServlet extends HttpServlet
{
private static final String modRcsId = "$Id: FccBrokerLoadServlet.java,v 1.1 2008/09/26 19:02:20 mayer Exp $";
private WebUtil webutil;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
HttpSession session = request.getSession(true);
String username = null;
response.setContentType("text/html");
//BEGIN - chrism - 07112008
//String tmpDir = Application.getBaseDir() + File.separatorChar + "www"
// + File.separatorChar + "html" + File.separatorChar
// + "scripts" + File.separatorChar + "AutoRefreshPage.js";
//File auto_refresh = new File(tmpDir);
PrintWriter out = response.getWriter();
if (session.isNew()) {
out.println("You have an invalid session or your session has expired");
out.println("<p>attempted security breach or session expried.</p>");
out.close(); //still searching for leak...
session = null; //still search for leak...
return;
} else {
username = (String) session.getAttribute("user.account");
out.close(); //not sure about the memory leak
session = null; //again?????
}
webutil = new WebUtil(username);
response.addHeader("Refresh", "30"); //testing java's auto-refresh
out.println(webutil.getHeader());
//END - chrism - 07112008
out.println("<div align=\"center\">");
//chrism 07112008
out.println("<p align=\"center\"><font size=\"5\" color=\"#FF0000\">Fremont Transportation Services Available Loads</font></p>");
out.println("<p align=\"center\">Thanks for your interest in FCC Transportation Services.</p>");
out.println("<p align=\"center\">This page is updated every 30 seconds. For detailed load information, including rates please contact us at:</p>");
out.println("<p align=\"center\">1-800-228-9842 Ext. 281</p>");
//BEGIN - chrism - 09302008
//OLD AUTO REFRESH java script that was being loaded.
/*try{
out.println(webutil.getHTMLString(auto_refresh));
} catch (Exception ex) {
ex.printStackTrace();
}*/
//OLD AUTO REFRESH java script that was being loaded.
//END - chrism - 09302008
out.println("<TABLE width=\"900\" cellspacing=\"1\" border=\"1\">");
out.println("<TR><TD width=\"75\" bgcolor=\"#FF0000\"><b>ORDER #</b></TD>");
out.println("<TD width=\"220\" bgcolor=\"#FF0000\"><p align=\"center\"><b>ORIGIN</b></TD>");
out.println("<TD width=\"155\" bgcolor=\"#FF0000\"><p align=\"center\"><b>PICKUP APPT.</b></TD>");
out.println("<TD width=\"220\" bgcolor=\"#FF0000\"><p align=\"center\"><b>DESTINATION</b></TD>");
out.println("<TD width=\"155\" bgcolor=\"#FF0000\"><p align=\"center\"><b>DELIVERY APPT.</b></TD>");
out.println("<TD width=\"75\" bgcolor=\"#FF0000\"><b>MILES</b></TD>");
out.println("<TD width=\"50\" bgcolor=\"#FF0000\"><b>TYPE</b></TD>");
out.println("<TD width=\"50\" bgcolor=\"#FF0000\"><b>LBS.</b></TD></TR>");
try {
getBrokerLoads(out);
} catch (Exception ex) {
ex.printStackTrace();
}
out.println("</TABLE>");
out.println("</div>");
out.println("<div align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=\"/servlet/com.tms.server.loadmaster. To Menu</strong></a> </font></div>");
out.println("</BODY>");
out.println("</HTML>");
out.close(); //testing memory leak problems....
session = null; //testing memory leak problems...
// response.flushBuffer();
}
public void getBrokerLoads(PrintWriter out)
{
try{
Query tmpQuery = DataFactory.createQuery();
tmpQuery.setTableName("movement");
tmpQuery.addField("origin.order_id order_id");
tmpQuery.addField("origin.city_name origin_city");
tmpQuery.addField("origin.state origin_state");
tmpQuery.addField("origin.sched_arrive_early pickup");
tmpQuery.addField("dest.city_name dest_city");
tmpQuery.addField("dest.state dest_state");
tmpQuery.addField("dest.sched_arrive_early delivery");
tmpQuery.addField("movement.move_distance");
tmpQuery.addField("orders.weight weight"); //chrism 07112008
tmpQuery.addField("orders.equipment_type_id trailer"); //chrism07142008
TableDescriptor originGroupTable = new TableDescriptor("stop origin",
"movement.origin_stop_id = origin.id", false);
tmpQuery.addJoin(originGroupTable);
TableDescriptor destGroupTable = new TableDescriptor("stop dest",
"movement.dest_stop_id = dest.id", false);
tmpQuery.addJoin(destGroupTable);
TableDescriptor ordersGroupTable = new TableDescriptor("orders",
"dest.order_id = orders.id", false);
tmpQuery.addJoin(ordersGroupTable);
tmpQuery.addWhere("movement.brokerage", "Y");
tmpQuery.addWhere("movement.status", "A");
tmpQuery.addOrderBy("origin.sched_arrive_early"); //chrism 08202008
tmpQuery.open();
while (tmpQuery.inBounds())
{
out.println("<TR><TD width=\"75\"><B><font size=\"2\">" + tmpQuery.getString("order_id") + "</FONT></B></TD>");
out.println("<TD width=\"220\"><p align=\"left\"><B><font size=\"2\">" + tmpQuery.getString("origin_city") + ", " + tmpQuery.getString("origin_state") + "</FONT></B></TD>");
out.println("<TD width=\"155\"><B><font size=\"2\">" + tmpQuery.getDate("pickup").toString() + "</FONT></B></TD>");
out.println("<TD width=\"220\"><p align=\"left\"><B><font size=\"2\">" + tmpQuery.getString("dest_city") + ", " + tmpQuery.getString("dest_state") + "</FONT></B></TD>");
out.println("<TD width=\"155\"><B><font size=\"2\">" + tmpQuery.getDate("delivery").toString() + "</FONT></B></TD>");
out.println("<TD width=\"75\"><B><font size=\"2\">" + tmpQuery.getString("movement.move_distance") + "</FONT></B></TD>");
out.println("<TD width=\"50\"><B><font size=\"2\">" + tmpQuery.getString("trailer") + "</FONT></B></TD>");
if(!tmpQuery.isNull("weight"))
out.println("<TD width=\"50\"><P align=\"right\"><B><font size=\"2\">" + tmpQuery.getString("weight") + "</FONT></B></P></TD></TR>");
else
out.println("<TD width=\"50\"><P align=\"right\"><B><font size=\"2\">0.0</FONT></B></P></TD></TR>");
tmpQuery.next();
}
tmpQuery.close();
}catch (Throwable ex){
ex.printStackTrace();
}
}
}
I have done everything I can think of and it still exsists.
The only thing I can think is that the page that is creates is set to refresh every 30 seconds, but I can not believe that I am the only one doing that....
Below is my code:
package com.tms.server.loadmaster.www;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.tms.common.remote.lib.data.Query;
import com.tms.common.lib.StringList;
import com.tms.common.remote.lib.data.DataFactory;
import com.tms.common.loadmaster.import com.tms.common.lib.data.TableDescriptor;
import com.tms.common.lib.Application;
/**
* <p>Title: FccBrokerLoadServlet</p>
* <p>Description: Web site listing of avaible broker loads</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Fremont Contract Carriers</p>
* @author not attributable
* @version 1.0
*/
public class FccBrokerLoadServlet extends HttpServlet
{
private static final String modRcsId = "$Id: FccBrokerLoadServlet.java,v 1.1 2008/09/26 19:02:20 mayer Exp $";
private WebUtil webutil;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws
ServletException, IOException
{
HttpSession session = request.getSession(true);
String username = null;
response.setContentType("text/html");
//BEGIN - chrism - 07112008
//String tmpDir = Application.getBaseDir() + File.separatorChar + "www"
// + File.separatorChar + "html" + File.separatorChar
// + "scripts" + File.separatorChar + "AutoRefreshPage.js";
//File auto_refresh = new File(tmpDir);
PrintWriter out = response.getWriter();
if (session.isNew()) {
out.println("You have an invalid session or your session has expired");
out.println("<p>attempted security breach or session expried.</p>");
out.close(); //still searching for leak...
session = null; //still search for leak...
return;
} else {
username = (String) session.getAttribute("user.account");
out.close(); //not sure about the memory leak
session = null; //again?????
}
webutil = new WebUtil(username);
response.addHeader("Refresh", "30"); //testing java's auto-refresh
out.println(webutil.getHeader());
//END - chrism - 07112008
out.println("<div align=\"center\">");
//chrism 07112008
out.println("<p align=\"center\"><font size=\"5\" color=\"#FF0000\">Fremont Transportation Services Available Loads</font></p>");
out.println("<p align=\"center\">Thanks for your interest in FCC Transportation Services.</p>");
out.println("<p align=\"center\">This page is updated every 30 seconds. For detailed load information, including rates please contact us at:</p>");
out.println("<p align=\"center\">1-800-228-9842 Ext. 281</p>");
//BEGIN - chrism - 09302008
//OLD AUTO REFRESH java script that was being loaded.
/*try{
out.println(webutil.getHTMLString(auto_refresh));
} catch (Exception ex) {
ex.printStackTrace();
}*/
//OLD AUTO REFRESH java script that was being loaded.
//END - chrism - 09302008
out.println("<TABLE width=\"900\" cellspacing=\"1\" border=\"1\">");
out.println("<TR><TD width=\"75\" bgcolor=\"#FF0000\"><b>ORDER #</b></TD>");
out.println("<TD width=\"220\" bgcolor=\"#FF0000\"><p align=\"center\"><b>ORIGIN</b></TD>");
out.println("<TD width=\"155\" bgcolor=\"#FF0000\"><p align=\"center\"><b>PICKUP APPT.</b></TD>");
out.println("<TD width=\"220\" bgcolor=\"#FF0000\"><p align=\"center\"><b>DESTINATION</b></TD>");
out.println("<TD width=\"155\" bgcolor=\"#FF0000\"><p align=\"center\"><b>DELIVERY APPT.</b></TD>");
out.println("<TD width=\"75\" bgcolor=\"#FF0000\"><b>MILES</b></TD>");
out.println("<TD width=\"50\" bgcolor=\"#FF0000\"><b>TYPE</b></TD>");
out.println("<TD width=\"50\" bgcolor=\"#FF0000\"><b>LBS.</b></TD></TR>");
try {
getBrokerLoads(out);
} catch (Exception ex) {
ex.printStackTrace();
}
out.println("</TABLE>");
out.println("</div>");
out.println("<div align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\"><a href=\"/servlet/com.tms.server.loadmaster. To Menu</strong></a> </font></div>");
out.println("</BODY>");
out.println("</HTML>");
out.close(); //testing memory leak problems....
session = null; //testing memory leak problems...
// response.flushBuffer();
}
public void getBrokerLoads(PrintWriter out)
{
try{
Query tmpQuery = DataFactory.createQuery();
tmpQuery.setTableName("movement");
tmpQuery.addField("origin.order_id order_id");
tmpQuery.addField("origin.city_name origin_city");
tmpQuery.addField("origin.state origin_state");
tmpQuery.addField("origin.sched_arrive_early pickup");
tmpQuery.addField("dest.city_name dest_city");
tmpQuery.addField("dest.state dest_state");
tmpQuery.addField("dest.sched_arrive_early delivery");
tmpQuery.addField("movement.move_distance");
tmpQuery.addField("orders.weight weight"); //chrism 07112008
tmpQuery.addField("orders.equipment_type_id trailer"); //chrism07142008
TableDescriptor originGroupTable = new TableDescriptor("stop origin",
"movement.origin_stop_id = origin.id", false);
tmpQuery.addJoin(originGroupTable);
TableDescriptor destGroupTable = new TableDescriptor("stop dest",
"movement.dest_stop_id = dest.id", false);
tmpQuery.addJoin(destGroupTable);
TableDescriptor ordersGroupTable = new TableDescriptor("orders",
"dest.order_id = orders.id", false);
tmpQuery.addJoin(ordersGroupTable);
tmpQuery.addWhere("movement.brokerage", "Y");
tmpQuery.addWhere("movement.status", "A");
tmpQuery.addOrderBy("origin.sched_arrive_early"); //chrism 08202008
tmpQuery.open();
while (tmpQuery.inBounds())
{
out.println("<TR><TD width=\"75\"><B><font size=\"2\">" + tmpQuery.getString("order_id") + "</FONT></B></TD>");
out.println("<TD width=\"220\"><p align=\"left\"><B><font size=\"2\">" + tmpQuery.getString("origin_city") + ", " + tmpQuery.getString("origin_state") + "</FONT></B></TD>");
out.println("<TD width=\"155\"><B><font size=\"2\">" + tmpQuery.getDate("pickup").toString() + "</FONT></B></TD>");
out.println("<TD width=\"220\"><p align=\"left\"><B><font size=\"2\">" + tmpQuery.getString("dest_city") + ", " + tmpQuery.getString("dest_state") + "</FONT></B></TD>");
out.println("<TD width=\"155\"><B><font size=\"2\">" + tmpQuery.getDate("delivery").toString() + "</FONT></B></TD>");
out.println("<TD width=\"75\"><B><font size=\"2\">" + tmpQuery.getString("movement.move_distance") + "</FONT></B></TD>");
out.println("<TD width=\"50\"><B><font size=\"2\">" + tmpQuery.getString("trailer") + "</FONT></B></TD>");
if(!tmpQuery.isNull("weight"))
out.println("<TD width=\"50\"><P align=\"right\"><B><font size=\"2\">" + tmpQuery.getString("weight") + "</FONT></B></P></TD></TR>");
else
out.println("<TD width=\"50\"><P align=\"right\"><B><font size=\"2\">0.0</FONT></B></P></TD></TR>");
tmpQuery.next();
}
tmpQuery.close();
}catch (Throwable ex){
ex.printStackTrace();
}
}
}