Class ClassLoaderContext

java.lang.Object
no.mnemonic.commons.utilities.ClassLoaderContext
All Implemented Interfaces:
AutoCloseable

public class ClassLoaderContext extends Object implements 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" }