当前位置: 代码迷 >> Java Web开发 >> java.lang.OutOfMemoryError: Java heap space 根源在哪里?该怎么解决
  详细解决方案

java.lang.OutOfMemoryError: Java heap space 根源在哪里?该怎么解决

热度:496   发布时间:2016-04-17 11:14:18.0
java.lang.OutOfMemoryError: Java heap space 根源在哪里?
我循环了很多次hibernate的save方法往数据库里插入数据,总会出现如下错误:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.microsoft.sqlserver.jdbc.TDSPacket.<init>(IOBuffer.java:3121)
at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3290)
at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4360)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:369)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:322)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4003)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1550)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:133)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:290)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
at com.dao.StandardinfoDAO.save(StandardinfoDAO.java:64)
at com.treat.StandInfo.<init>(StandInfo.java:135)
at com.treat.StartLog.main(StartLog.java:21)

------解决方案--------------------
JSP文件太大了?
------解决方案--------------------
增加内存不能解决根本 你找下是不是什么资源没释放什么的
------解决方案--------------------
关于这个问题,首先楼主,你应该加大你服务器的内存(比如Tomcat),然后再看看你服务器中JVM关于内存的设置,JVM的的内存分为永久储存区(常用的api的class)和堆空间,堆空间分为新生区和养老去,新生区分为伊迪园区和幸存者一区以及幸存者二区,一般我们new出来的都会在伊迪园区中产生,随着伊迪园区的内存的使用,会将一些new出来的变量放到幸存者一区(过程中的算法,多数采用根集法衍生出来的算法),以此类推到幸存者二区,等到这个三个区满了以后,就会报内存溢出。这样的话 楼主可以去看看自己的JVM的设置,当然 这这是从JVM的角度来分析 如果从程序自身来看 楼主也可以去分析一下
------解决方案--------------------
支持5#的
------解决方案--------------------
学习了,看看
------解决方案--------------------
  相关解决方案