use SimpleClassLoaderLifeCycle by default

This commit is contained in:
Sebastian Sdorra
2020-02-12 12:36:37 +01:00
parent 56b8dbdb22
commit bca34b829d
6 changed files with 22 additions and 19 deletions

View File

@@ -19,17 +19,17 @@ public abstract class ClassLoaderLifeCycle implements LifeCycle {
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycle.class);
@VisibleForTesting
static final String PROPERTY = "sonia.scm.classloading.lifecycle";
static final String PROPERTY = "sonia.scm.lifecycle.classloading";
public static ClassLoaderLifeCycle create() {
ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
String implementation = System.getProperty(PROPERTY);
if (SimpleClassLoaderLifeCycle.NAME.equalsIgnoreCase(implementation)) {
LOG.info("create new simple ClassLoaderLifeCycle");
return new SimpleClassLoaderLifeCycle(webappClassLoader);
if (ClassLoaderLifeCycleWithLeakPrevention.NAME.equalsIgnoreCase(implementation)) {
LOG.info("create new ClassLoaderLifeCycle with leak prevention");
return new ClassLoaderLifeCycleWithLeakPrevention(webappClassLoader);
}
LOG.info("create new ClassLoaderLifeCycle with leak prevention");
return new ClassLoaderLifeCycleWithLeakPrevention(webappClassLoader);
LOG.info("create new simple ClassLoaderLifeCycle");
return new SimpleClassLoaderLifeCycle(webappClassLoader);
}
private final ClassLoader webappClassLoader;

View File

@@ -26,6 +26,8 @@ import static se.jiderhamn.classloader.leak.prevention.cleanup.ShutdownHookClean
*/
final class ClassLoaderLifeCycleWithLeakPrevention extends ClassLoaderLifeCycle {
public static final String NAME = "with-leak-prevention";
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycleWithLeakPrevention.class);
private Deque<ClassLoaderAndPreventor> classLoaders = new ArrayDeque<>();