use of edu.iu.dsc.tws.local.util.LocalClassLoader in project twister2 by DSC-SPIDAL.
the class LocalSubmitter method startWorker.
/**
* This method starts a new worker instance on a separate thread.
*/
private static Thread startWorker(Twister2Job twister2Job, Config config, int workerId, CyclicBarrier cyclicBarrier) {
Thread.UncaughtExceptionHandler hndler = (th, ex) -> {
failed = true;
fault = ex;
};
LocalClassLoader localClassLoader = new LocalClassLoader(LocalSubmitter.class.getClassLoader());
localClassLoader.addJobClass(twister2Job.getWorkerClass());
try {
Object o = localClassLoader.loadClass(MockWorker.class.getName()).getConstructor(twister2Job.getClass(), config.getClass(), Integer.class, CyclicBarrier.class).newInstance(twister2Job, config, workerId, cyclicBarrier);
Thread thread = new Thread((Runnable) o);
thread.setName("worker-" + workerId);
thread.setUncaughtExceptionHandler(hndler);
thread.start();
return thread;
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new Twister2RuntimeException("Failed to start the worker thread", e);
}
}
Aggregations