public interface ThreadContextClassLoaderHolder
Specification for how to restore the original ThreadContext ClassLoader to a Thread. When we support JDK 1.7, this should really be an extension of AutoCloseable instead, to support the try-with-resources pattern. Typical use:
// Create and set the ThreadContext ClassLoader
ThreadContextClassLoaderHolder holder = null;
try {
holder = ThreadContextClassLoaderBuilder.createFor(getClass())
.addPath("some/path")
.addURL(someURL)
.addPaths(aPathList)
.buildAndSet();
// ... perform operations using the newly set ThreadContext ClassLoader...
} finally {
// Restore the original ClassLoader
holder.restoreClassLoaderAndReleaseThread();
}
Modifier and Type | Method and Description |
---|---|
String |
getClassPathAsArgument()
Retrieves the ClassPath held by this ThreadContextClassLoaderHolder as a
File.pathSeparatorChar -separated string. |
void |
restoreClassLoaderAndReleaseThread()
Restores the original ThreadContext ClassLoader, and nullifies
any references to the Thread which had its ThreadContext
ClassLoader altered.
|
void restoreClassLoaderAndReleaseThread()
String getClassPathAsArgument()
File.pathSeparatorChar
-separated string. This is directly usable as a String argument by
any external process.Copyright © 2005–2015 MojoHaus. All rights reserved.