/** * Spawns a new thread for the given {@link Runnable}. * * @param namePrefix the name prefix for the thread * @param runnable the {@link Runnable} to execute * @return the created thread */ public Thread spawn(String namePrefix, Runnable runnable) { checkNotNull(namePrefix, "namePrefix can't be null"); checkNotNull(runnable, "runnable can't be null"); String name = getName(namePrefix); Thread thread; if (throwException) { thread = new ThrowExceptionThread(name, runnable); thread.setUncaughtExceptionHandler(exceptionHandler); } else { thread = new ReportExceptionThread(identifier, name, runnable); } threads.add(thread); thread.start(); return thread; }