public class SingleClassloaderExecutor extends AbstractClassloaderExecutor
SingleClassloaderExecutor cle = new SingleClassloaderExecutor(myClassloader); cle.execute(new Runnable() { public void run() { myObject.myMethod(); } });What happens is that the entire object graph of myObject is deep-cloned into the
myClassloader
classloader
and then the myObject.myMethod()
is executed.
You can also execute methods that return something:
SingleClassloaderExecutor cle = new SingleClassloaderExecutor(myClassloader); MyResult result = cle.execute(new CallableHere we imagine that() { public MyResult call() throws Exception { return myObject.myMethod(); } });
myObject.myMethod()
returns an object of type MyResult
. Again the entire
state will be deep-cloned to myClassloader
and then the myObject.myMethod()
is executed.
The result of the method call is deep-cloned back into the original classloader (the one that made the call to
cle.execute(..)
) and is ready for use.
Note that the SingleClassloaderExecutor requires a deep cloner implementing the DeepClonerSPI
present in the class-path.
Constructor and Description |
---|
SingleClassloaderExecutor(ClassLoader classloader) |
Modifier and Type | Method and Description |
---|---|
protected Object |
execute(Object instance,
Method method,
Object... arguments) |
execute, execute
public SingleClassloaderExecutor(ClassLoader classloader)
Copyright © 2007–2019. All rights reserved.