java内存泄漏笔记之二

1,weblogic8.1默认是不能运行在jdk5和jdk6上的,原因是weblogic8的mbean为1.0版本,而jdk5和jdk6自带的mbean版本要高(为1.1?)
 
  可以在环境变量里配置一个参数,设置mbean=1.0,然后weblogic8.1就能运行在jdk5和jdk6上了,但这样据说会产生其他问题。参见
 
2,如何分析MAT里那个leak饼图?
  那个饼图分为好几块,除了Remainder外,其他好几块的名字都是以Problem Suspect开始的,看样子内存泄漏不可能发生在Remainder

3, 有人说 如果98%的时间是用于GC且可用的 Heap size 不足2%,才会产生内存溢出?

4,如何在jdk6配置内存溢出时是否产生dump文件
  可以在jdk6的jconsole的MBean的com.sun.management的HotSpotDiagnostic MBeanHotSpotDiagnostic MBean的第3个调用里,
  设置p0为HeapDumpOnOutOfMemoryError,p1为true,然后点击setVMOption按钮。
   则内存溢出时会自动创建一个java_pid<pid>.hprof的堆dump(转储)文件,默认存放工作空间下(例如tomcat的bin目录)
   
   先把tomcat的内存设置得很小,再跑应用,后台很快就报以下错误:
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid5736.hprof ...
Heap dump file created [87840650 bytes in 4.488 secs]
2009-2-4 19:17:59 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run
严重: Caught exception (java.lang.OutOfMemoryError: Java heap space) executing org.apache.tomcat.util.net.TcpWorkerThread@a77785, terminating thread
2009-2-4 19:18:02 org.apache.tomcat.util.net.TcpWorkerThread runIt
严重: Unexpected error
java.lang.OutOfMemoryError: Java heap space
2009-2-4 19:18:04 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run
严重: Caught exception (java.lang.OutOfMemoryError: Java heap space) executing org.apache.tomcat.util.net.TcpWorkerThread@a77785, terminating thread
Exception in thread "DefaultQuartzScheduler_QuartzSchedulerThread" java.lang.OutOfMemoryError: Java heap space
2009-2-4 19:18:05 org.apache.coyote.http11.Http11Processor process
严重: Error processing request
java.lang.OutOfMemoryError: Java heap space
2009-2-4 19:18:13 org.apache.coyote.http11.Http11Processor process
严重: Error finishing response
java.lang.OutOfMemoryError: Java heap space
Hibernate: select......这里它抽空还执行了一条sql
.........略.............................
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Timer-0" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: Java heap space
.........略.............................

 在输出错误日志的过程中,不知何故还会在eclipse的debug里不停的调用java.util.concurrent.ThreadPoolExecutor

5,内存溢出时自动生成的dump文件和未溢出时自己用jmap导出的dump文件的leak饼图有很大区别,我感觉前者的分析要有用一些。具体区别:
  (1)后者有org.apache.catalina.loader.WebappClassLoader和ZipFileIndex,而前者没有
  (2)两者都有org.hibernate.impl.SessionFactoryImpl
  (3)前者有如下的关键信息:

8,980 instances of "java.lang.Class", loaded by "<system class loader>" occupy 8,208,768 (12.43%) bytes.

Biggest instances:

  • class org.springframework.beans.CachedIntrospectionResults @ 0x735f808 - 2,218,536 (3.36%) bytes. These instances are referenced from one instance of "java.lang.Thread", loaded by "<system class loader>"


  • 6,一个疑问,为何无人访问时Tomcat的内存图是锯齿形的

    7,我配置了-XX:+HeapDumpOnCtrlBreak,用的jdk1.5.0_14
    结果Ctrl+Break 时报
    Unable to create java_pid3072.hprof.m27.10/05/07M20: No such file or directory
    在 这里 找到了原因,是jdk的一个bug( bug id:6454676),This problem has been fixed in 1.4.2_18 and 5.0u17

    8,前两个1g的顶峰处,是tomcat自己进行的gc。后面的几个是我自己手动gc的

    heap.jpg

    9,

    7,002 instances of "java.lang.Class", loaded by "<system class loader>" occupy 12,359,912 (11.20%) bytes.

    Biggest instances:

  • class sun.rmi.server.UnicastServerRef @ 0x51b16a48 - 4,447,432 (4.03%) bytes.
  • class sun.rmi.transport.ObjectTable @ 0x51b40330 - 3,491,160 (3.16%) bytes
  • 问题

    你可能感兴趣的:(java内存泄漏笔记之二)