做了一个小网站 jsp +servlet +hibernate  tomcat5.5
上线之后总是   运行一段时间一会就出现内存溢出的错误....
访问量不大---
所有的conn stmt pstmt 全部关闭---
整个工程里就一个嵌套循环----也没有死循环----
可是为什么内存就是释放不了呢????
是不是tomcat设置问题啊
个人感觉设置了内存也没什么用啊 只是拖延dowm的时间..哪位高手 有根本解决办法 请告诉小弟 谢谢
一下是程序实例:
daoImpl实例:
package com.hongqiao.dao.impl;import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;import com.hongqiao.dao.CommonDao;
import com.hongqiao.util.ConnectionUtil;
import com.hongqiao.util.SessionUtil;public class CommonDaoImpl implements CommonDao { public void delete(Object o) {
Session session = null;
Transaction tran = null;
try {
session = SessionUtil.openSession();
tran = session.beginTransaction();
session.delete(o);
tran.commit();
} catch (HibernateException e) {
tran.rollback();
e.printStackTrace();
} finally {
if (session != null)
session.close();
}
} public Object get(Class clazz, Serializable id) {
Session session = null;
try {
session = SessionUtil.openSession();
return session.get(clazz, id);
} catch (HibernateException e) {
e.printStackTrace();
} finally {
if (session != null)
session.close();
}
return null;
} public void save(Object o) { Session session = null;
Transaction tran = null;
try {
session = SessionUtil.openSession();
tran = session.beginTransaction();
session.save(o);
tran.commit();
} catch (HibernateException e) {
tran.rollback();
e.printStackTrace();
} finally {
if (session != null)
session.close();
}
} public void update(Object o) { Session session = null;
Transaction tran = null;
try {
session = SessionUtil.openSession();
tran = session.beginTransaction();
session.update(o);
tran.commit();
} catch (HibernateException e) {
tran.rollback();
e.printStackTrace();
} finally {
if (session != null)
session.close();
}
}JSP实例:  只发了头部
<%@ page language="java"
import="java.util.*,com.hongqiao.dao.*,com.hongqiao.dao.impl.*,com.hongqiao.entity.*,javax.servlet.http.HttpSession"
pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
String userid = request.getParameter("userid");
UserLoginDao dao = new UserLoginDaoImpl();
String userName = dao.getByUserid(Integer.valueOf(userid))
.getName();
request.setAttribute("userName", userName); HttpSession session1 = request.getSession();
Userlogin user = (Userlogin) session1.getAttribute("user");
boolean login = user != null;
request.setAttribute("login", new Boolean(login));
request.setAttribute("nologin", new Boolean(!login));
if (user != null) {
String userid2 = user.getUserid().toString();
String power = user.getPower();
boolean self = userid2.equals(userid);
boolean master = power.equals("m");
boolean artist=power.equals("a");
boolean ma= master||artist;
request.setAttribute("artist",new Boolean(ma));
boolean masterorself = self || master;
boolean masterself = self && master;
request.setAttribute("self", new Boolean(self));
request.setAttribute("master", new Boolean(master));
request.setAttribute("masterorself", new Boolean(masterorself));
String name = user.getName();
request.setAttribute("username", name);
request.setAttribute("masterself", new Boolean(masterself));
} else {
request.setAttribute("master", new Boolean(false));
}
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'HomePage.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
<!--var flag=false;
function DrawImage(ImgD)
{var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0)
{
flag=true;
if(image.width/image.height>= 130/90)
{ if(image.width>130)
{

ImgD.width=130;
ImgD.height=(image.height*130)/image.width;
}
else
{

ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else
{
if(image.height>90)
{

ImgD.height=90;
ImgD.width=(image.width*90)/image.height;
}
else
{

ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}

}
}//-->

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>

解决方案 »

  1.   

    麻烦使用源代码的方式重新发一下你这个~~看着头疼啊。还有就是tomcat是不用怀疑的 它的内存回收就是java的内存回收仔细检查一下你的其他代码。
      

  2.   

    用UFO试试,用UFO做网站的web server绝对不出现内存溢出的现象
      

  3.   

    用工具察看一下,
    如jprofile等
    看看内存的消耗情况
      

  4.   

    tomcat配置里把虚拟内存改成1024M,它默认的是64M
      

  5.   

    恩。调试下 先。 重新加载下,在弄,应该不能是tomcat的问题