/** * Runs callable tasks each in separate threads. * * @param calls Callable tasks. * @param threadName Thread name. * @return Execution time in milliseconds. * @throws Exception If failed. */ public static long runMultiThreaded(Iterable<Callable<?>> calls, String threadName) throws Exception { return runMultiThreaded(calls, new GridTestSafeThreadFactory(threadName)); }
threads.add(threadFactory.newThread(call)); threadFactory.checkError();
/** * Interrupts and waits for termination of all the threads started * so far by current test. * * @param log Logger. */ public static void stopThreads(IgniteLogger log) { busyLock.block(); try { GridTestSafeThreadFactory.stopAllThreads(log); } finally { busyLock.unblock(); } }
final GridTestSafeThreadFactory thrFactory = new GridTestSafeThreadFactory(threadName); thrFactory.newThread(() -> { try {
@Override public boolean cancel() throws IgniteCheckedException { super.cancel(); if (isDone()) return false; thrFactory.interruptAllThreads(); try { get(); return false; } catch (IgniteFutureCancelledCheckedException e) { return true; } catch (IgniteCheckedException e) { return false; } } };
/** * Create new thread around runnable task. * * @param r Runnable task to execute in the thread. * @return New thread around runnable task. * @see GridTestThread */ @Override public Thread newThread(final Runnable r) { return newThread(GridTestUtils.makeCallable(r, null)); }
@Override public boolean cancel() throws IgniteCheckedException { super.cancel(); if (isDone()) return false; runFut.cancel(); threadFactory.interruptAllThreads(); return onCancelled(); } };
final GridTestSafeThreadFactory threadFactory = new GridTestSafeThreadFactory(threadName);