Giter Site home page Giter Site logo

ggeda / classloader-leak-prevention Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mjiderhamn/classloader-leak-prevention

0.0 1.0 0.0 1.06 MB

ClassLoader leak prevention / protection

Home Page: http://java.jiderhamn.se/2012/03/04/classloader-leaks-vi-this-means-war-leak-prevention-library/

License: Apache License 2.0

Java 100.00%

classloader-leak-prevention's Introduction

Classloader Leak Prevention library

Build Status Maven Central License

If you want to avoid the dreaded java.lang.OutOfMemoryError: Metaspace / PermGen space, just include this library into your Java EE application, and add this context listener in your web.xml:

<listener>
  <listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor</listener-class>
</listener>

It makes sense to keep this listener "outermost" (initializing first, destroying last), so you should normally declare it before any other listeners in web.xml.

To learn more about classloader leaks, their causes, types, ways to find them and known offenders, see blog series here: http://java.jiderhamn.se/category/classloader-leaks/

Maven

The library is available in Maven Central with the following details:

<dependency>
  <groupId>se.jiderhamn</groupId>
  <artifactId>classloader-leak-prevention</artifactId>
  <version>1.15.2</version>
</dependency>

Configuration

The context listener has a number of settings that can be configured with context parameters in web.xml:

<context-param>
  <param-name>ClassLoaderLeakPreventor.stopThreads</param-name>
  <param-value>false</param-value>
</context-param>

The available settings are

Parameter name Default value Description
ClassLoaderLeakPreventor.stopThreads true Should threads tied to the web app classloader be forced to stop at application shutdown?
ClassLoaderLeakPreventor.stopTimerThreads true Should Timer threads tied to the web app classloader be forced to stop at application shutdown?
ClassLoaderLeakPreventor.executeShutdownHooks true Should shutdown hooks registered from the application be executed at application shutdown?
ClassLoaderLeakPreventor.startOracleTimeoutThread true Should the oracle.jdbc.driver.OracleTimeoutPollingThread thread be forced to start with system ClassLoader, in case Oracle JDBC driver is present? This is normally a good idea, but can be disabled in case the Oracle JDBC driver is not used even though it is on the classpath.
ClassLoaderLeakPreventor.threadWaitMs 5000
(5 seconds)
No of milliseconds to wait for threads to finish execution, before stopping them.
ClassLoaderLeakPreventor.shutdownHookWaitMs 10000
(10 seconds)
No of milliseconds to wait for shutdown hooks to finish execution, before stopping them. If set to -1 there will be no waiting at all, but Thread is allowed to run until finished.

Classloader leak detection / test framework

The test framework now has its own Maven module and its own documentation, see classloader-leak-test-framework

License

This project is licensed under the Apache 2 license, which allows you to include modified versions of the code in your distributed software, without having to release your source code.

classloader-leak-prevention's People

Contributors

arlol avatar candrews avatar hazendaz avatar kmoens avatar marcelstoer avatar nuzayats avatar seanf avatar yagee-de avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.