购买的是腾讯云服务器,4核8G,windows2003系统。但在使用过程, 老是报java.lang.OutOfMemoryError: Java heap space。截取其中一部分日志请大家看下有什么好的解决方法:
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-nio-8001-exec-1" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "NioBlockingSelector.BlockPoller-1" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-nio-8001-exec-11" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-nio-8001-ClientPoller-1" .java:606) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) at com.zssoft.gas.intercept.LoginIntercept.intercept(LoginIntercept.java:68) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.zssoft.gas.intercept.ThreadLocalIntercept.intercept(ThreadLocalIntercept.java:26) at com.jfinal.aop.Invocation.invoke(Invocation.java:67) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:82) at com.zssoft.gas.handler.BasePathHandler.handle(BasePathHandler.java:35) at com.zssoft.gas.handler.ServletFilterHandler.handle(ServletFilterHandler.java:32) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
除了内存泄漏以外,还有一种情况是内存回收的速度跟不上内存被吃掉的速度,例如:在有一定访问量的情况下,某个地方在不停的创建对象,好比 Db.find("select * from bigTable") 这种 select * 并且不带 where 条件的查询会生成很多对象
还有更专业的工具在 eclipse 中就可以查看,例如 jprofile 之类的
一般不需要复杂工具,用用 jmap 与 jstack 就好,参考这里:http://hillside.iteye.com/blog/706129