mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
use SimpleClassLoaderLifeCycle by default
This commit is contained in:
@@ -200,10 +200,6 @@
|
||||
<name>java.awt.headless</name>
|
||||
<value>true</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>sonia.scm.classloading.lifecycle</name>
|
||||
<value>simple</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
<webApp>
|
||||
<contextPath>/scm</contextPath>
|
||||
|
||||
@@ -734,10 +734,6 @@
|
||||
<name>scm.stage</name>
|
||||
<value>${scm.stage}</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>sonia.scm.classloading.lifecycle</name>
|
||||
<value>simple</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
@@ -823,10 +819,6 @@
|
||||
<name>scm.home</name>
|
||||
<value>target/scm-it</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>sonia.scm.classloading.lifecycle</name>
|
||||
<value>simple</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
<jettyXml>${project.basedir}/src/main/conf/jetty.xml</jettyXml>
|
||||
<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.
|
||||
* <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 {
|
||||
|
||||
|
||||
@@ -19,18 +19,18 @@ 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 simple ClassLoaderLifeCycle");
|
||||
return new SimpleClassLoaderLifeCycle(webappClassLoader);
|
||||
}
|
||||
|
||||
private final ClassLoader webappClassLoader;
|
||||
|
||||
|
||||
@@ -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<>();
|
||||
|
||||
@@ -18,8 +18,19 @@ class ClassLoaderLifeCycleTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateDefaultClassLoader() {
|
||||
void shouldCreateWithLeakPreventionClassLoader() {
|
||||
System.setProperty(ClassLoaderLifeCycle.PROPERTY, ClassLoaderLifeCycleWithLeakPrevention.NAME);
|
||||
try {
|
||||
ClassLoaderLifeCycle classLoaderLifeCycle = ClassLoaderLifeCycle.create();
|
||||
assertThat(classLoaderLifeCycle).isInstanceOf(ClassLoaderLifeCycleWithLeakPrevention.class);
|
||||
} finally {
|
||||
System.clearProperty(ClassLoaderLifeCycle.PROPERTY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateDefaultClassLoader() {
|
||||
ClassLoaderLifeCycle classLoaderLifeCycle = ClassLoaderLifeCycle.create();
|
||||
assertThat(classLoaderLifeCycle).isInstanceOf(SimpleClassLoaderLifeCycle.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user