Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ce6e8b3e38b8
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 74a4cd0a2aa6
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Apr 24, 2013

  1. Stopping all threads that reference the openmrs class loader during

    shutdown: Investigate possible memory leak in 1.9.0 or one of its
    bundled modules. - TRUNK-3440
    dkayiwa committed Apr 24, 2013
    Copy the full SHA
    8e59fd5 View commit details
  2. Merge pull request #289 from dkayiwa/TRUNK-3440

    Stopping all threads that reference the openmrs class loader during shutdown: Investigate possible memory leak in 1.9.0 or one of its bundled modules. - TRUNK-3440
    dkayiwa committed Apr 24, 2013

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    74a4cd0 View commit details
Showing with 31 additions and 0 deletions.
  1. +31 −0 api/src/main/java/org/openmrs/util/OpenmrsClassLoader.java
31 changes: 31 additions & 0 deletions api/src/main/java/org/openmrs/util/OpenmrsClassLoader.java
Original file line number Diff line number Diff line change
@@ -374,6 +374,37 @@ private static List<Thread> listThreads(ThreadGroup group, String indent) {
}

public static void onShutdown() {

//Since we are shutting down, stop all threads that reference the openmrs class loader.
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
for (Thread thread : threadArray) {

ClassLoader classLoader = thread.getContextClassLoader();

//Threads like Finalizer, Reference Handler, etc have null class loader reference.
if (classLoader == null)
continue;

if (classLoader instanceof OpenmrsClassLoader) {
try {
//Set to WebappClassLoader just in case stopping fails.
thread.setContextClassLoader(classLoader.getParent());

//Stopping the current thread will halt all current cleanup.
//So do not ever ever even attempt stopping it. :)
if (thread == Thread.currentThread())
continue;

log.info("onShutdown Stopping thread: " + thread.getName());
thread.stop();
}
catch (Throwable ex) {
log.error(ex.getMessage(), ex);
}
}
}

clearReferences();
}