有关ContainerBackgroundProcessor的错误

时间:2014-04-10 13:20:06

标签: java ajax hibernate servlets out-of-memory

我如何防止这种情况?

当我使用ajax更新配置文件详细信息时会发生这种情况。我在ajax调用中调用updateprofile servlet .heap memory是605487104

Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: Java heap space
    at java.util.concurrent.ConcurrentHashMap$Values.iterator(Unknown Source)
    at java.util.AbstractCollection.toArray(Unknown Source)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1427)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:301)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "http-bio-8080-exec-8" java.lang.OutOfMemoryError: Java heap space
    at com.mysql.jdbc.Buffer.getBytes(Buffer.java:198)
    at com.mysql.jdbc.Buffer.readLenByteArray(Buffer.java:318)
    at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1366)
    at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2333)
    at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:435)
    at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2040)
    at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1443)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1777)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
    at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3293)
    at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
    at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
    at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
    at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
    at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
    at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1005)
    at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
    at com.dao.StudentService.updateEducationStudentProfile(StudentService.java:469)
    at com.controller.Student.UpdateStudentProfileServlet.service(UpdateStudentProfileServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

我的updateprofile.jsp从DAO调用updateprofile函数..

        if(request.getParameter("educationdetail").equals("yes"))
        {

         String school10= request.getParameter("school10");
         String board10= request.getParameter("board10");        
         double mark10= Double.parseDouble(request.getParameter("mark10"));

         String school12= request.getParameter("schoool12");
         String board12= request.getParameter("board12");
         double mark12= Double.parseDouble(request.getParameter("mark12"));

         String ugname= request.getParameter("ugname");
         String uguniversity= request.getParameter("uguniversity");     
         double ugmark= Double.parseDouble(request.getParameter("ugmark"));

         String pgname = null,pguniversity=null;
         double pgmark = 0;
         long heapsize=Runtime.getRuntime().totalMemory();


        Runtime runtime = Runtime.getRuntime();
        // Run the garbage collector
        runtime.gc();

        StudentService objStudentService = new StudentService();
          objStudentService.updateEducationStudentProfile(request.getSession(false).getAttribute("student_studentid").toString(), school10, board10, mark10, school12, board12, mark12, ugname, uguniversity, ugmark, pgname, pguniversity, pgmark);

1 个答案:

答案 0 :(得分:1)

您需要查看JVM内存参数。实际上,您可以根据需要为JVM设置尽可能多的内存,但这并不能防止内存泄漏,但重要的是要知道:

-Xmx2048m -> this param to set the max memory that the JVM can allocate
-Xms1024m -> the init memory that JVM will allocate on the start up
-XX:MaxPermSize=512M -> this for the max Permanent Generation memory

所以在你的情况下,你可以设置与另一台机器一样多的内存。所以你的机器不会占用比Xmx

更多的RAM

并且您可能还想检查此参数,这将阻止Premature对象。并加快GC活动

-XX:MaxNewSize=  
-XX:NewSize=614m// 614 is an example value, it good to set it by 30% of your xmx value.

你也可以告诉你JVM使用什么类型的GC:

-XX:+UseConcMarkSweepGC