final MethodInvocation copy = (MethodInvocation) invocation.copy();
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
FutureResult result = new FutureResult();
Runnable command = result.setter(new Callable()
{
public Object call() throws Exception
{
try
{
Thread.currentThread().setContextClassLoader(cl);
return copy.invokeNext();
}
catch (Throwable throwable)
{
if (throwable instanceof Exception)
{
throw ((Exception) throwable);
}
else
throw new Exception(throwable);
}
}
});
executor.execute(command);
return new FutureImpl(result);