/** * Stop the consuming thread. */ public void stop() throws InterruptedException { _shouldStop = true; // This method could be called either when we get an ONLINE transition or // when we commit a segment and replace the realtime segment with a committed // one. In the latter case, we don't want to call join. if (Thread.currentThread() != _consumerThread) { Uninterruptibles.joinUninterruptibly(_consumerThread, 10, TimeUnit.MINUTES); if (_consumerThread.isAlive()) { segmentLogger.warn("Failed to stop consumer thread within 10 minutes"); } } }
void joinSuccessfully() { Uninterruptibles.joinUninterruptibly(thread); completed.assertCompletionExpected(); assertEquals(Thread.State.TERMINATED, thread.getState()); }
public void testJoinWithNoWait() throws InterruptedException { Stopwatch stopwatch = Stopwatch.createStarted(); Thread thread = new Thread(new JoinTarget(15)); thread.start(); thread.join(); assertFalse(thread.isAlive()); joinUninterruptibly(thread); joinUninterruptibly(thread, 0, MILLISECONDS); joinUninterruptibly(thread, -42, MILLISECONDS); joinUninterruptibly(thread, LONG_DELAY_MS, MILLISECONDS); assertTimeNotPassed(stopwatch, LONG_DELAY_MS); }
void joinSuccessfully(long timeoutMillis) { Uninterruptibles.joinUninterruptibly(thread, timeoutMillis, MILLISECONDS); completed.assertCompletionExpected(); assertEquals(Thread.State.TERMINATED, thread.getState()); }
/** * Close the DomainSocketWatcher and wait for its thread to terminate. * * If there is more than one close, all but the first will be ignored. */ @Override public void close() throws IOException { lock.lock(); try { if (closed) return; if (LOG.isDebugEnabled()) { LOG.debug(this + ": closing"); } closed = true; } finally { lock.unlock(); } // Close notificationSockets[0], so that notificationSockets[1] gets an EOF // event. This will wake up the thread immediately if it is blocked inside // the select() system call. notificationSockets[0].close(); // Wait for the select thread to terminate. Uninterruptibles.joinUninterruptibly(watcherThread); }
private static List<Throwable> runThreadsAndReturnExceptions(int numThreads, Runnable task) { List<Thread> threads = new ArrayList<>(numThreads); final List<Throwable> exceptions = new ArrayList<>(numThreads); for (int i = 0; i < numThreads; i++) { Thread thread = new Thread(task); thread.setUncaughtExceptionHandler( new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { exceptions.add(e); } }); threads.add(thread); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { Uninterruptibles.joinUninterruptibly(t); } return exceptions; }
void joinUnsuccessfully(long timeoutMillis) { Uninterruptibles.joinUninterruptibly(thread, timeoutMillis, MILLISECONDS); completed.assertCompletionNotExpected(timeoutMillis); assertFalse(Thread.State.TERMINATED.equals(thread.getState())); } }
/** * Test for a bug where threads weren't getting signaled when shutdown was called, only when tasks * completed. */ public void testDirectExecutorService_awaitTermination_missedSignal() { final ExecutorService service = MoreExecutors.newDirectExecutorService(); Thread waiter = new Thread() { @Override public void run() { try { service.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException e) { return; } } }; waiter.start(); awaitTimedWaiting(waiter); service.shutdown(); Uninterruptibles.joinUninterruptibly(waiter, 10, TimeUnit.SECONDS); if (waiter.isAlive()) { waiter.interrupt(); fail("awaitTermination failed to trigger after shutdown()"); } }
private static void verifyOccupiedMethodsInAnotherThread( final Monitor monitor, boolean expectedIsOccupied, boolean expectedIsOccupiedByCurrentThread, int expectedOccupiedDepth) { final AtomicBoolean actualIsOccupied = new AtomicBoolean(); final AtomicBoolean actualIsOccupiedByCurrentThread = new AtomicBoolean(); final AtomicInteger actualOccupiedDepth = new AtomicInteger(); final AtomicReference<Throwable> thrown = new AtomicReference<>(); joinUninterruptibly( startThread( new Runnable() { @Override public void run() { try { actualIsOccupied.set(monitor.isOccupied()); actualIsOccupiedByCurrentThread.set(monitor.isOccupiedByCurrentThread()); actualOccupiedDepth.set(monitor.getOccupiedDepth()); } catch (Throwable t) { thrown.set(t); } } })); assertNull(thrown.get()); assertEquals(expectedIsOccupied, actualIsOccupied.get()); assertEquals(expectedIsOccupiedByCurrentThread, actualIsOccupiedByCurrentThread.get()); assertEquals(expectedOccupiedDepth, actualOccupiedDepth.get()); } }
Uninterruptibles.joinUninterruptibly(thread);
/** * Stops and removes all volume scanners.<p/> * * This function will block until all the volume scanners have stopped. */ public synchronized void removeAllVolumeScanners() { for (Entry<String, VolumeScanner> entry : scanners.entrySet()) { entry.getValue().shutdown(); } for (Entry<String, VolumeScanner> entry : scanners.entrySet()) { Uninterruptibles.joinUninterruptibly(entry.getValue(), 5, TimeUnit.MINUTES); } scanners.clear(); }
/** * Stops and removes a volume scanner.<p/> * * This function will block until the volume scanner has stopped. * * @param volume The volume to remove. */ public synchronized void removeVolumeScanner(FsVolumeSpi volume) { if (!isEnabled()) { LOG.debug("Not removing volume scanner for {}, because the block " + "scanner is disabled.", volume.getStorageID()); return; } VolumeScanner scanner = scanners.get(volume.getStorageID()); if (scanner == null) { LOG.warn("No scanner found to remove for volumeId {}", volume.getStorageID()); return; } LOG.info("Removing scanner for volume {} (StorageID {})", volume, volume.getStorageID()); scanner.shutdown(); scanners.remove(volume.getStorageID()); Uninterruptibles.joinUninterruptibly(scanner, 5, TimeUnit.MINUTES); }
t.setContextClassLoader(classLoader); t.start(); joinUninterruptibly(t); } else { runTests(classLoader, testFiles, exceptions);
@Override public synchronized void close() { running = false; Uninterruptibles.joinUninterruptibly(thread); }
private void joinProcessors() { log.debug("pushing terminating bundles to {} processors", queues.length); for (int i = 0; i < queues.length; i++) { pushQueue(i, TERM_BUNDLE); } for (Thread thread : threads) { Uninterruptibles.joinUninterruptibly(thread); } }
void joinSuccessfully() { Uninterruptibles.joinUninterruptibly(thread); completed.assertCompletionExpected(); assertEquals(Thread.State.TERMINATED, thread.getState()); }
@Override public void edit(NodeBuilder builder) { builder.getChildNode("foo").getChildNode("bar").remove(); nodeRemoved.countDown(); // wait until r1 commits joinUninterruptibly(t); } });
@Override public void edit(NodeBuilder builder) { builder.getChildNode("foo").getChildNode("bar").child("qux"); nodeAdded.countDown(); // wait until r2 commits joinUninterruptibly(t); } });
/** * Test that a java interruption can stop the watcher thread */ @Test(timeout=60000) public void testInterruption() throws Exception { final DomainSocketWatcher watcher = newDomainSocketWatcher(10); watcher.watcherThread.interrupt(); Uninterruptibles.joinUninterruptibly(watcher.watcherThread); watcher.close(); }
/** * Test that a java interruption can stop the watcher thread */ @Test(timeout=60000) public void testInterruption() throws Exception { final DomainSocketWatcher watcher = newDomainSocketWatcher(10); watcher.watcherThread.interrupt(); Uninterruptibles.joinUninterruptibly(watcher.watcherThread); watcher.close(); }