Package no.mnemonic.commons.utilities
Class ClassLoaderContext
java.lang.Object
no.mnemonic.commons.utilities.ClassLoaderContext
- All Implemented Interfaces:
AutoCloseable
A classloader context simplifies switching the current thread classloader for the
duration of a code block, and ensures that the current thread classloader is reset
to original value at the end of the code block.
Object obj = loadObjectFromNonSystemClassLoader(...);
try (ClassLoaderContext ctx = ClassLoaderContext.of(obj)) {
//invoke code which needs to use the classloader of "obj"
}
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static ClassLoaderContext
of
(ClassLoader cl) static ClassLoaderContext
-
Method Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
of
-
of
-
getContextClassLoader
-