九个哥 2015-04-14 04:04 采纳率: 0%
浏览 3912

jvm内存怎么设置,以及如何优化代码

写了一个web程序,可以根据输入的内容抓取网口信息以及串口信息,分别使用了:
Jpcap.dll,rxtxSerial.dll
单独开一个测试时正常,但是同时开两个抓取,tomcat就会挂掉,然后生成一个:
hs_err_pidXXXX.log文件
于是百度了一下,感觉是jvm内存的问题,就调整了一下:
-Xms1024m -Xmx1024m -Xmn600m -XX:PermSize=653m -XX:MaxPermSize=653m -XX:ParallelGCThreads=4
调试过程中发现-XX:PermSize过小服务器就会死机,不知道是什么原因,哪位大神如果知道希望给我解答一下.
服务器比较老,是win2003,4G的内存,发现无法调大了,但是错误依然存在,我截取了部分我觉得有用的错误代码:

 GC Heap History (8 events):
Event: 4.269 GC heap before
{Heap before GC invocations=0 (full 0):
 def new generation   total 552960K, used 491520K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K, 100% used [0x02b60000, 0x20b60000, 0x20b60000)
  from space 61440K,   0% used [0x20b60000, 0x20b60000, 0x24760000)
  to   space 61440K,   0% used [0x24760000, 0x24760000, 0x28360000)
 tenured generation   total 434176K, used 0K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   0% used [0x28360000, 0x28360000, 0x28360200, 0x42b60000)
 compacting perm gen  total 667648K, used 8941K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   1% used [0x42b60000, 0x4341b4a0, 0x4341b600, 0x6b760000)
No shared spaces configured.
Event: 4.429 GC heap after
Heap after GC invocations=1 (full 0):
 def new generation   total 552960K, used 61440K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K,   0% used [0x02b60000, 0x02b60000, 0x20b60000)
  from space 61440K, 100% used [0x24760000, 0x28360000, 0x28360000)
  to   space 61440K,   0% used [0x20b60000, 0x20b60000, 0x24760000)
 tenured generation   total 434176K, used 13941K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   3% used [0x28360000, 0x290fd510, 0x290fd600, 0x42b60000)
 compacting perm gen  total 667648K, used 8941K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   1% used [0x42b60000, 0x4341b4a0, 0x4341b600, 0x6b760000)
No shared spaces configured.
}
Event: 7.331 GC heap before
{Heap before GC invocations=1 (full 0):
 def new generation   total 552960K, used 552960K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K, 100% used [0x02b60000, 0x20b60000, 0x20b60000)
  from space 61440K, 100% used [0x24760000, 0x28360000, 0x28360000)
  to   space 61440K,   0% used [0x20b60000, 0x20b60000, 0x24760000)
 tenured generation   total 434176K, used 13941K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   3% used [0x28360000, 0x290fd510, 0x290fd600, 0x42b60000)
 compacting perm gen  total 667648K, used 14009K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   2% used [0x42b60000, 0x4390e4e0, 0x4390e600, 0x6b760000)
No shared spaces configured.
Event: 7.469 GC heap after
Heap after GC invocations=2 (full 0):
 def new generation   total 552960K, used 60265K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K,   0% used [0x02b60000, 0x02b60000, 0x20b60000)
  from space 61440K,  98% used [0x20b60000, 0x2463a6f0, 0x24760000)
  to   space 61440K,   0% used [0x24760000, 0x24760000, 0x28360000)
 tenured generation   total 434176K, used 34836K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   8% used [0x28360000, 0x2a5652c0, 0x2a565400, 0x42b60000)
 compacting perm gen  total 667648K, used 14009K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   2% used [0x42b60000, 0x4390e4e0, 0x4390e600, 0x6b760000)
No shared spaces configured.
}
Event: 36.600 GC heap before
{Heap before GC invocations=2 (full 0):
 def new generation   total 552960K, used 551785K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K, 100% used [0x02b60000, 0x20b60000, 0x20b60000)
  from space 61440K,  98% used [0x20b60000, 0x2463a6f0, 0x24760000)
  to   space 61440K,   0% used [0x24760000, 0x24760000, 0x28360000)
 tenured generation   total 434176K, used 34836K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   8% used [0x28360000, 0x2a5652c0, 0x2a565400, 0x42b60000)
 compacting perm gen  total 667648K, used 24620K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   3% used [0x42b60000, 0x4436b0b0, 0x4436b200, 0x6b760000)
No shared spaces configured.
Event: 36.714 GC heap after
Heap after GC invocations=3 (full 0):
 def new generation   total 552960K, used 30082K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K,   0% used [0x02b60000, 0x02b60000, 0x20b60000)
  from space 61440K,  48% used [0x24760000, 0x264c08f0, 0x28360000)
  to   space 61440K,   0% used [0x20b60000, 0x20b60000, 0x24760000)
 tenured generation   total 434176K, used 41289K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   9% used [0x28360000, 0x2abb2550, 0x2abb2600, 0x42b60000)
 compacting perm gen  total 667648K, used 24620K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   3% used [0x42b60000, 0x4436b0b0, 0x4436b200, 0x6b760000)
No shared spaces configured.
}
Event: 86.711 GC heap before
{Heap before GC invocations=3 (full 0):
 def new generation   total 552960K, used 521602K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K, 100% used [0x02b60000, 0x20b60000, 0x20b60000)
  from space 61440K,  48% used [0x24760000, 0x264c08f0, 0x28360000)
  to   space 61440K,   0% used [0x20b60000, 0x20b60000, 0x24760000)
 tenured generation   total 434176K, used 41289K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   9% used [0x28360000, 0x2abb2550, 0x2abb2600, 0x42b60000)
 compacting perm gen  total 667648K, used 25095K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   3% used [0x42b60000, 0x443e1e08, 0x443e2000, 0x6b760000)
No shared spaces configured.
Event: 86.754 GC heap after
Heap after GC invocations=4 (full 0):
 def new generation   total 552960K, used 14048K [0x02b60000, 0x28360000, 0x28360000)
  eden space 491520K,   0% used [0x02b60000, 0x02b60000, 0x20b60000)
  from space 61440K,  22% used [0x20b60000, 0x21918378, 0x24760000)
  to   space 61440K,   0% used [0x24760000, 0x24760000, 0x28360000)
 tenured generation   total 434176K, used 41289K [0x28360000, 0x42b60000, 0x42b60000)
   the space 434176K,   9% used [0x28360000, 0x2abb2550, 0x2abb2600, 0x42b60000)
 compacting perm gen  total 667648K, used 25095K [0x42b60000, 0x6b760000, 0x6b760000)
   the space 667648K,   3% used [0x42b60000, 0x443e1e08, 0x443e2000, 0x6b760000)
No shared spaces configured.
}

感觉Xmn还是小了,于是用自己的8G内存的电脑也试了一下:
-Xms2048m -Xmx2048m -Xmn1500m -XX:PermSize=800m -XX:MaxPermSize=800m -XX:ParallelGCThreads=4
错误还在,
eden space 1152000K, 100% used
感觉Xmn依然小了
第一次遇见这种问题,感觉既然单条任务可以,两条任务我把内存已经调大好几倍应该不会有问题了,但是问题依然存在,应该不单单是调整JVM的问题了,只能上网求助了

  • 写回答

1条回答 默认 最新

  • tdw2011 2015-04-14 04:10
    关注

    在网上搜到的一个链接,感觉不错,http://www.cnblogs.com/mingforyou/archive/2012/03/03/2378143.html,最后有讲直接设置perm size,因为这部分内存一般由类本身决定,不是由类的实例引起

    评论

报告相同问题?

悬赏问题

  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。