ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
BasicTaskRunnable runnable = new BasicTaskRunnable(classLoader);
runnable.setTestEjbSecurity(testEjbSecurity);
Runnable task = (Runnable)contextService.createContextObject(runnable, new Class [] {Runnable.class});
RunnableWrapper wrapper = new RunnableWrapper(task);
Thread t = new Thread(wrapper);
t.start();
t.join();
Throwable throwable = wrapper.getThrowable();
if (throwable instanceof Exception) {
throw (Exception)throwable;
} else if (throwable instanceof Error) {
throw (Error)throwable;
}