mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
use SimpleClassLoaderLifeCycle by default
This commit is contained in:
@@ -200,10 +200,6 @@
|
|||||||
<name>java.awt.headless</name>
|
<name>java.awt.headless</name>
|
||||||
<value>true</value>
|
<value>true</value>
|
||||||
</systemProperty>
|
</systemProperty>
|
||||||
<systemProperty>
|
|
||||||
<name>sonia.scm.classloading.lifecycle</name>
|
|
||||||
<value>simple</value>
|
|
||||||
</systemProperty>
|
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<webApp>
|
<webApp>
|
||||||
<contextPath>/scm</contextPath>
|
<contextPath>/scm</contextPath>
|
||||||
|
|||||||
@@ -734,10 +734,6 @@
|
|||||||
<name>scm.stage</name>
|
<name>scm.stage</name>
|
||||||
<value>${scm.stage}</value>
|
<value>${scm.stage}</value>
|
||||||
</systemProperty>
|
</systemProperty>
|
||||||
<systemProperty>
|
|
||||||
<name>sonia.scm.classloading.lifecycle</name>
|
|
||||||
<value>simple</value>
|
|
||||||
</systemProperty>
|
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
||||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||||
@@ -823,10 +819,6 @@
|
|||||||
<name>scm.home</name>
|
<name>scm.home</name>
|
||||||
<value>target/scm-it</value>
|
<value>target/scm-it</value>
|
||||||
</systemProperty>
|
</systemProperty>
|
||||||
<systemProperty>
|
|
||||||
<name>sonia.scm.classloading.lifecycle</name>
|
|
||||||
<value>simple</value>
|
|
||||||
</systemProperty>
|
|
||||||
</systemProperties>
|
</systemProperties>
|
||||||
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
||||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Restart strategy which tries to free, every resource used by the context, starts gc and re initializes the context.
|
* Restart strategy which tries to free, every resource used by the context, starts gc and re initializes the context.
|
||||||
|
* <strong>Warning: </strong> This strategy should only be used with an classloader lifecycle which protects the
|
||||||
|
* created plugin classloader from classloader leaks.
|
||||||
*/
|
*/
|
||||||
class InjectionContextRestartStrategy implements RestartStrategy {
|
class InjectionContextRestartStrategy implements RestartStrategy {
|
||||||
|
|
||||||
|
|||||||
@@ -19,17 +19,17 @@ public abstract class ClassLoaderLifeCycle implements LifeCycle {
|
|||||||
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycle.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycle.class);
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String PROPERTY = "sonia.scm.classloading.lifecycle";
|
static final String PROPERTY = "sonia.scm.lifecycle.classloading";
|
||||||
|
|
||||||
public static ClassLoaderLifeCycle create() {
|
public static ClassLoaderLifeCycle create() {
|
||||||
ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
String implementation = System.getProperty(PROPERTY);
|
String implementation = System.getProperty(PROPERTY);
|
||||||
if (SimpleClassLoaderLifeCycle.NAME.equalsIgnoreCase(implementation)) {
|
if (ClassLoaderLifeCycleWithLeakPrevention.NAME.equalsIgnoreCase(implementation)) {
|
||||||
LOG.info("create new simple ClassLoaderLifeCycle");
|
LOG.info("create new ClassLoaderLifeCycle with leak prevention");
|
||||||
return new SimpleClassLoaderLifeCycle(webappClassLoader);
|
return new ClassLoaderLifeCycleWithLeakPrevention(webappClassLoader);
|
||||||
}
|
}
|
||||||
LOG.info("create new ClassLoaderLifeCycle with leak prevention");
|
LOG.info("create new simple ClassLoaderLifeCycle");
|
||||||
return new ClassLoaderLifeCycleWithLeakPrevention(webappClassLoader);
|
return new SimpleClassLoaderLifeCycle(webappClassLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ClassLoader webappClassLoader;
|
private final ClassLoader webappClassLoader;
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import static se.jiderhamn.classloader.leak.prevention.cleanup.ShutdownHookClean
|
|||||||
*/
|
*/
|
||||||
final class ClassLoaderLifeCycleWithLeakPrevention extends ClassLoaderLifeCycle {
|
final class ClassLoaderLifeCycleWithLeakPrevention extends ClassLoaderLifeCycle {
|
||||||
|
|
||||||
|
public static final String NAME = "with-leak-prevention";
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycleWithLeakPrevention.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ClassLoaderLifeCycleWithLeakPrevention.class);
|
||||||
|
|
||||||
private Deque<ClassLoaderAndPreventor> classLoaders = new ArrayDeque<>();
|
private Deque<ClassLoaderAndPreventor> classLoaders = new ArrayDeque<>();
|
||||||
|
|||||||
@@ -17,9 +17,20 @@ class ClassLoaderLifeCycleTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldCreateWithLeakPreventionClassLoader() {
|
||||||
|
System.setProperty(ClassLoaderLifeCycle.PROPERTY, ClassLoaderLifeCycleWithLeakPrevention.NAME);
|
||||||
|
try {
|
||||||
|
ClassLoaderLifeCycle classLoaderLifeCycle = ClassLoaderLifeCycle.create();
|
||||||
|
assertThat(classLoaderLifeCycle).isInstanceOf(ClassLoaderLifeCycleWithLeakPrevention.class);
|
||||||
|
} finally {
|
||||||
|
System.clearProperty(ClassLoaderLifeCycle.PROPERTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldCreateDefaultClassLoader() {
|
void shouldCreateDefaultClassLoader() {
|
||||||
ClassLoaderLifeCycle classLoaderLifeCycle = ClassLoaderLifeCycle.create();
|
ClassLoaderLifeCycle classLoaderLifeCycle = ClassLoaderLifeCycle.create();
|
||||||
assertThat(classLoaderLifeCycle).isInstanceOf(ClassLoaderLifeCycleWithLeakPrevention.class);
|
assertThat(classLoaderLifeCycle).isInstanceOf(SimpleClassLoaderLifeCycle.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user