@Override public void process(final KeyFilter filter, final CacheLoaderTask task, Executor executor, boolean fetchValue, boolean fetchMetadata) { scanForUnknownDirectories(); ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor); eacs.submit(new Callable<Void>() { @Override public Void call() throws Exception { eacs.waitUntilAllCompleted(); if (eacs.isExceptionThrown()) { throw new PersistenceException("Execution exception!", eacs.getFirstException());
public void testExceptions() { ExecutorAllCompletionService service = createService(1); service.submit(new WaitRunnable(1), null); service.submit(new ExceptionRunnable("second"), null); service.submit(new WaitRunnable(1), null); service.submit(new ExceptionRunnable("third"), null); service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); assertEquals("second", findCause(service.getFirstException()).getMessage()); }
private ExecutorAllCompletionService createService(int maxThreads) { if (lastExecutorService != null) { lastExecutorService.shutdownNow(); } lastExecutorService = Executors.newFixedThreadPool(maxThreads, getTestThreadFactory("Worker")); return new ExecutorAllCompletionService(lastExecutorService); }
eacs.submit(new Runnable() { @Override public void run() {
@Override public void process(final KeyFilter filter, final CacheLoaderTask task, Executor executor, boolean fetchValue, boolean fetchMetadata) { scanForUnknownDirectories(); ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(executor); eacs.submit(new Callable<Void>() { @Override public Void call() throws Exception { eacs.waitUntilAllCompleted(); if (eacs.isExceptionThrown()) { throw new PersistenceException("Execution exception!", eacs.getFirstException());
public void testWaitForAll() { ExecutorAllCompletionService service = createService(1); long before = System.currentTimeMillis(); service.submit(new WaitRunnable(500), null); service.submit(new WaitRunnable(500), null); service.waitUntilAllCompleted(); long after = System.currentTimeMillis(); assertTrue(after - before >= 1000); assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }
return; ExecutorAllCompletionService eacs = new ExecutorAllCompletionService(threadPool); EntityManager emStream = emf.createEntityManager(); try { emStream.close(); eacs.waitUntilAllCompleted(); if (eacs.isExceptionThrown()) { throw new JpaStoreException(eacs.getFirstException());
public void testParallelWait() throws InterruptedException { final ExecutorAllCompletionService service = createService(2); for (int i = 0; i < 300; ++i) { service.submit(new WaitRunnable(10), null); } List<Thread> threads = new ArrayList<>(10); for (int i = 0; i < 10; ++i) { Thread t = new Thread(() -> { service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }); threads.add(t); t.start(); } for (Thread t : threads) { t.join(); } assertTrue(service.isAllCompleted()); assertFalse(service.isExceptionThrown()); }
public void testParallelException() throws InterruptedException { final ExecutorAllCompletionService service = createService(2); for (int i = 0; i < 150; ++i) { service.submit(new WaitRunnable(10), null); } service.submit(new ExceptionRunnable("foobar"), null); for (int i = 0; i < 150; ++i) { service.submit(new WaitRunnable(10), null); } List<Thread> threads = new ArrayList<>(10); for (int i = 0; i < 10; ++i) { Thread t = new Thread(() -> { service.waitUntilAllCompleted(); assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); }); threads.add(t); t.start(); } for (Thread t : threads) { t.join(); } assertTrue(service.isAllCompleted()); assertTrue(service.isExceptionThrown()); }