ClassLoader Leak - Are they worth solving?

后端 未结 5 1881
暖寄归人
暖寄归人 2021-02-07 17:03

ClassLoader leaks usually result in java.lang.OutOfMemoryError: PermGen. In the instance of working on application servers you may see this as a result of

5条回答
  •  再見小時候
    2021-02-07 18:06

    Those are one of the worst leaks... but any leak is evil. So, I, personally, resolve them. Profiling helps as well. There are no easy ways per se but:

    • Threads go into threadGroups +starter thread for each module to ensure new Threads() have that group.
    • Special care of the Thread.inheritedAccessControlContext (which holds a reference to the classloader)
    • WeakReferences when you need to keep classes, actually use WeakReferences for listeners, so no one can skip de-registers (and use only annon. clasess). Having the framework for WeakListeners does help.
    • Extra care for DB drives, java.security.Provider
    • few more tricks (incl. dynamic enhance of class files but that's overkill usually)

    bottom line:


    leaks are evil.

提交回复
热议问题