Chinaunix首页 | 论坛 | 博客
  • 博客访问: 447663
  • 博文数量: 173
  • 博客积分: 2970
  • 博客等级: 少校
  • 技术积分: 1490
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-11 14:35
文章存档

2011年(9)

2010年(17)

2009年(62)

2008年(85)

我的朋友

分类: Java

2010-09-29 09:11:20

PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决方法也一定是加大内存。说说为什么会内存益出:这一部分用于存放Class和Meta的信息,Class在被 Load的时候被放入PermGen space区域,它和和存放Instance的Heap区域不同,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,所以如果你的APP会LOAD很多CLASS的话,就很可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。

改正方法,在 run.bat 中加入:-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

因为项目中引用了很多的 jar 包,而这些 jar 包中的 class 信息会被 JBoss 的 class loader 加载到 PermGen space 区域,在 JVM 默认的情况下,该部分空间的大小只有 4M,在 jar 包非常多的情况下,显然是不够用的,所以通过 -XX:MaxPermSize=256m 指定最大值后即可解决问题。

   另外,如果 heap 内存不足出现 java.lang.OutOfMemoryError: Java heap space 时,可以通过 -Xmx512m 指定最大 heap 内存来解决这样的问题。

   run.bat样例如下:

Java代码
  1. @echo off   
  2. rem -------------------------------------------------------------------------   
  3. rem JBoss Bootstrap Script for Win32   
  4. rem -------------------------------------------------------------------------   
  5.   
  6. rem $Id: run.bat 73584 2008-05-22 12:09:26Z dimitris@jboss.org $   
  7.   
  8. @if not "%ECHO%" == ""   echo %ECHO%   
  9. @if "%OS%" == "Windows_NT"   setlocal   
  10.   
  11. set DIRNAME=.\   
  12. if "%OS%" == "Windows_NT" set DIRNAME=%~dp0%   
  13. set PROGNAME=run.bat   
  14. if "%OS%" == "Windows_NT" set PROGNAME=%~nx0%   
  15.   
  16. pushd %DIRNAME%..   
  17. set JBOSS_HOME=%CD%   
  18. popd   
  19.   
  20. REM Add bin/native to the PATH if present   
  21. if exist "%JBOSS_HOME%\bin\native" set PATH=%JBOSS_HOME%\bin\native;%PATH%   
  22. if exist "%JBOSS_HOME%\bin\native" set JAVA_OPTS=%JAVA_OPTS% -Djava.library.path="%PATH%"  
  23.   
  24. rem Find run.jar, or we can't continue  
  25.   
  26. set RUNJAR=%JBOSS_HOME%\bin\run.jar   
  27. if exist "%RUNJAR%" goto FOUND_RUN_JAR   
  28. echo Could not locate %RUNJAR%. Please check that you are in the   
  29. echo bin directory when running this script.   
  30. goto END   
  31.   
  32. :FOUND_RUN_JAR   
  33.   
  34. if not "%JAVA_HOME%" == "" goto ADD_TOOLS   
  35.   
  36. set JAVA=java   
  37.   
  38. echo JAVA_HOME is not set.   Unexpected results may occur.   
  39. echo Set JAVA_HOME to the directory of your local JDK to avoid this message.   
  40. goto SKIP_TOOLS   
  41.   
  42. :ADD_TOOLS   
  43.   
  44. set JAVA=%JAVA_HOME%\bin\java   
  45.   
  46. rem A full JDK with toos.jar is not required anymore since jboss web packages   
  47. rem the eclipse jdt compiler and javassist has its own internal compiler.   
  48. if not exist "%JAVA_HOME%\lib\tools.jar" goto SKIP_TOOLS   
  49.   
  50. rem If exists, point to the JDK javac compiler in case the user wants to   
  51. rem later override the eclipse jdt compiler for compiling JSP pages.   
  52. set JAVAC_JAR=%JAVA_HOME%\lib\tools.jar   
  53.   
  54. :SKIP_TOOLS   
  55.   
  56. rem If JBOSS_CLASSPATH or JAVAC_JAR is empty, don't include it, as this will   
  57. rem result in including the local directory in the classpath, which makes   
  58. rem error tracking harder.   
  59. if not "%JAVAC_JAR%" == "" set RUNJAR=%JAVAC_JAR%;%RUNJAR%   
  60. if "%JBOSS_CLASSPATH%" == "" set RUN_CLASSPATH=%RUNJAR%   
  61. if "%RUN_CLASSPATH%" == "" set RUN_CLASSPATH=%JBOSS_CLASSPATH%;%RUNJAR%   
  62.   
  63. set JBOSS_CLASSPATH=%RUN_CLASSPATH%   
  64.   
  65. rem Setup JBoss specific properties   
  66. set JAVA_OPTS=%JAVA_OPTS% -Dprogram.name=%PROGNAME%   
  67.   
  68. rem Add -server to the JVM options, if supported   
  69. "%JAVA%" -server -version 2>&1 | findstr /I hotspot > nul   
  70. if not errorlevel == 1 (set JAVA_OPTS=%JAVA_OPTS% -server)   
  71.   
  72. rem JVM memory allocation pool parameters. Modify as appropriate.   
  73. set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m   
  74.   
  75. rem With Sun JVMs reduce the RMI GCs to once per hour   
  76. set JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000  
  77.   
  78. rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.   
  79. rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%   
  80.   
  81. rem Setup the java endorsed dirs   
  82. set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed   
  83.   
  84. echo ===============================================================================   
  85. echo.   
  86. echo   JBoss Bootstrap Environment   
  87. echo.   
  88. echo    JBOSS_HOME: %JBOSS_HOME%   
  89. echo.   
  90. echo    JAVA: %JAVA%   
  91. echo.   
  92. echo   JAVA_OPTS: %JAVA_OPTS%   
  93. echo.   
  94. echo    CLASSPATH: %JBOSS_CLASSPATH%   
  95. echo.   
  96. echo ===============================================================================   
  97. echo.   
  98.   
  99. :RESTART   
  100. "%JAVA%" %JAVA_OPTS% ^   
  101.     -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%" ^   
  102.     -classpath "%JBOSS_CLASSPATH%" ^   
  103.     org.jboss.Main %*   
  104.   
  105. if ERRORLEVEL 10 goto RESTART   
  106.   
  107. :END   
  108. if "%NOPAUSE%" == "" pause   
  109.   
  110. :END_NO_PAUSE  
阅读(2075) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-29 11:36:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2010-09-29 11:36:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2010-09-29 11:15:12

很高兴认识你,看看我的博客中的文章吧,对生活很有好处,下面是一些推荐的链接。 电脑一族必看的科学饮食 http://blog.chinaunix.net/u3/119126/showart_2337806.html 抵御电脑辐射从吃开始 http://blog.chinaunix.net/u3/119126/showart_2337785.html 上班族的五种防病食物 http://blog.chinaunix.net/u3/119126/showart_2337764.html 哪些人群最应该喝酸奶 http://blog.chinaunix.net/u3/119126/showart_2337734.html 计算机族必喝的健康饮料 http://blog.chinaunix.net/u3/119126/showart_2337676.html

chinaunix网友2010-09-29 11:15:12

很高兴认识你,看看我的博客中的文章吧,对生活很有好处,下面是一些推荐的链接。 电脑一族必看的科学饮食 http://blog.chinaunix.net/u3/119126/showart_2337806.html 抵御电脑辐射从吃开始 http://blog.chinaunix.net/u3/119126/showart_2337785.html 上班族的五种防病食物 http://blog.chinaunix.net/u3/119126/showart_2337764.html 哪些人群最应该喝酸奶 http://blog.chinaunix.net/u3/119126/showart_2337734.html 计算机族必喝的健康饮料 http://blog.chinaunix.net/u3/119126/showart_2337676.html