New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

se.jiderhamn:classloader-leak-prevention

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

se.jiderhamn:classloader-leak-prevention

ServletContextListener that prevents ClassLoader leaks / java.lang.OutOfMemoryError: PermGen space

  • 1.15.4
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

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.3</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 nameDefault valueDescription
ClassLoaderLeakPreventor.stopThreadstrueShould threads tied to the web app classloader be forced to stop at application shutdown?
ClassLoaderLeakPreventor.stopTimerThreadstrueShould Timer threads tied to the web app classloader be forced to stop at application shutdown?
ClassLoaderLeakPreventor.executeShutdownHookstrueShould shutdown hooks registered from the application be executed at application shutdown?
ClassLoaderLeakPreventor.startOracleTimeoutThreadtrue 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.threadWaitMs5000
(5 seconds)
No of milliseconds to wait for threads to finish execution, before stopping them.
ClassLoaderLeakPreventor.shutdownHookWaitMs10000
(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.

FAQs

Package last updated on 30 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc