修改: - play ~run
来运行我的项目
如何删除此问题,
我的项目正处于测试阶段。每天5-6小时后它会突然停止并发出以下错误。
该怎么做才能消除这个错误?
我正在使用playframework 2.2
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
Caused by: java.lang.OutOfMemoryError: PermGen space
at sun.misc.Unsafe.defineClass(Native Method)
at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:399)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:396)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:395)
at sun.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:113)
at sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:331)
at java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1376)
at java.io.ObjectStreamClass.access$1500(ObjectStreamClass.java:72)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:493)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468)
at java.security.AccessController.doPrivileged(Native Method)
at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:468)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365)
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:602)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1706)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1344)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: PermGen space
[error] Total time: 11065 s, completed 8 Feb, 2014 6:12:52 PM
1. Waiting for source changes... (press enter to interrupt)
java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 4 s, completed 8 Feb, 2014 6:12:57 PM
2. Waiting for source changes... (press enter to interrupt)
java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 4 s, completed 8 Feb, 2014 6:13:08 PM
3. Waiting for source changes... (press enter to interrupt)
java.lang.OutOfMemoryError: PermGen space
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) java.lang.reflect.InvocationTargetException
[error] Total time: 6 s, completed 8 Feb, 2014 6:13:54 PM
4. Waiting for source changes... (press enter to interrupt)
[error] Expected letter
[error] Expected symbol
[error] Expected '!'
[error] Expected '+'
[error] Expected '++'
[error] Expected ';'
[error] Expected end of input.
[error] Expected 'show'
[error] Expected '*'
[error] Expected '{'
[error] Expected project ID
[error] Expected configuration
[error] Expected key
[error] 9000
[error] ^
sbt appears to be exiting abnormally.
The log file for this session is at /tmp/sbt7580663022166474466.log
java.lang.OutOfMemoryError: PermGen space
Error during sbt execution: java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-125" java.lang.OutOfMemoryError: PermGen space
答案 0 :(得分:9)
我遇到了同样的问题所以我导出了SBT_OPTS
,如下所示:
export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:PermSize=512M -XX:MaxPermSize=1024M"
答案 1 :(得分:3)
通常,这意味着您没有为JVM提供足够的内存,或者您有内存泄漏。了解人们如何解决此类问题:Dealing with "java.lang.OutOfMemoryError: PermGen space" error或搜索非播放特定错误:“java.lang.OutOfMemoryError:PermGen”。
查看您的日志,我注意到您可能正在从SBT或其他一些构建工具(如Maven(“等待源更改...”))运行它。为了帮助SBT防止内存泄漏,您可以在午餐时添加这些参数:
java -Xms128M -Xmx1200M -Xss20M -XX:MaxPermSize=1200m -XX:+CMSClassUnloadingEnabled -jar `dirname $0`/sbt-launch.jar "$@"
注意类卸载命令行arg。总的来说,我注意到无论你做什么,在SBT中运行的应用程序仍会设置泄漏资源,但在生产中它不会发生。您可以尝试以分叉JVM模式运行以帮助SBT - 例如,请参阅SBT-Revolver插件。如果你想真正了解你的应用程序如何消耗内存以及它是否有内存泄漏,那么在构建工具之外运行它,即将它部署到容器(如Tomcat)或运行jar或者你有什么。您可以附加jconsole
之类的工具来观察内存使用情况。
答案 2 :(得分:2)
首先启动JVM时增加perm gen大小。
描述您的代码并找出为什么消耗perm gen。
查找从不发布引用,深度递归任务等的集合。
答案 3 :(得分:2)
您的代码会生成许多类。类存储在PermGen空间中,永远不会被垃圾回收(在Java 8之前)。运行JVM时,可以使用-XXMaxPermSize
选项增加PermGen空间,例如:
-XX:MaxPermSize=512M
使用-Xmx
或-Xms
(堆空间)不起作用,因为这是一个不同的空间。
您也可以使用Java 8 JVM,因为它不再使用PermGen。
答案 4 :(得分:-1)
您可以使用jconsole.exe(JDK的一部分)来查看PermGen大小增加的趋势。可能会在某个时间间隔内增加,因此您可以更轻松地进行调试。另外,尝试增加PermGen大小:Increase permgen space。 但如果问题出现在代码中,那么很长一段时间都没有用......