public void stop() { try { flush(); } catch (IOException e) { LOGGER.error("Error flushing", e); } try { close(); } catch (IOException e) { LOGGER.error("Error closing", e); } try { backgroundFlushTask.shutdown(); // Wait a while for existing tasks to terminate if (!backgroundFlushTask.awaitTermination(15, TimeUnit.SECONDS)) { backgroundFlushTask.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!backgroundFlushTask.awaitTermination(15, TimeUnit.SECONDS)) { LOGGER.error("Stream did not terminate"); } } } catch (InterruptedException ie) { // (Re-)Cancel if current thread also interrupted backgroundFlushTask.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } }
public synchronized void stop() { if (executor == null) { return; } executor.shutdownNow(); executor = null; printExecutor.shutdownNow(); printExecutor = null; scriptRunner = null; }
public synchronized void stopIndexing() { if (submittingExecutor != null) { submittingExecutor.shutdownNow(); submittingExecutor = null; } if (indexingExecutor != null) { indexingExecutor.shutdownNow(); indexingExecutor = null; } writeLastAccessTime(); }
private void shutdownExecutor() { if (executor != null) { executor.shutdown(); try { if (!executor.awaitTermination(1, TimeUnit.SECONDS)) { executor.shutdownNow(); } } catch (InterruptedException e) { executor.shutdownNow(); } } }
/** * {@inheritDoc} * * <p>This implementation will call <code>shutdownNow()</code> on the wrapped * ScheduledExecutorService if requested during construction. Otherwise, it always do nothing and * return an empty list. */ public List<Runnable> shutdownNow() { if (forwardShutdown) { return schedExec.shutdownNow(); } else { return Collections.emptyList(); } }
public void testBlockingTake() throws InterruptedException { final CoalescedPipe<String> coalescedPipe = new CoalescedPipe<String>(); ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); scheduledExecutorService.schedule( new Runnable() { public void run() { try { coalescedPipe.put("test1"); } catch (InterruptedException ie) { fail(ie.getMessage()); } } }, 500, TimeUnit.MILLISECONDS); long startTime = System.currentTimeMillis(); assertEquals("test1", coalescedPipe.take()); assertTrue((System.currentTimeMillis() - startTime) > 250L); scheduledExecutorService.shutdownNow(); scheduledExecutorService.awaitTermination(120, TimeUnit.SECONDS); }
@AfterClass public void tearDown() { if (executor != null) { executor.shutdownNow(); executor = null; } }
public static void main(String[] args) { /* cancelExec.schedule(new Runnable() { @Override public void run() { System.out.println("run"); } },1,TimeUnit.SECONDS); */ Runnable r = new Runnable() { @Override public void run() { System.out.println("run"); } }; try { timeRun(r, 2, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } cancelExec.shutdownNow(); }
@After public void tearDown() throws Exception { scheduledThreadPool.shutdownNow(); while (CurrentUnitOfWork.isStarted()) { CurrentUnitOfWork.get().rollback(); } }
public void stop() { Utilities.close(prototype); if (taskFuture != null) { taskFuture.cancel(true); } scheduleService.shutdownNow(); }
@Override protected void onClose(int status) { if (scheduler != null) { System.out.println("da close"); scheduler.shutdownNow(); } }
@Test(groups = "short") public void should_throttle_requests() { // Throttle to a very low value. Even a single thread can generate a higher throughput. final int maxRequests = 10; cluster .getConfiguration() .getPoolingOptions() .setMaxRequestsPerConnection(HostDistance.LOCAL, maxRequests); // Track in flight requests in a dedicated thread every second final AtomicBoolean excessInflightQueriesSpotted = new AtomicBoolean(false); final Host host = cluster.getMetadata().getHost(new InetSocketAddress(CCMBridge.IP_PREFIX + "1", 9042)); ScheduledExecutorService openConnectionsWatcherExecutor = Executors.newScheduledThreadPool(1); final Runnable openConnectionsWatcher = new Runnable() { @Override public void run() { int inFlight = session.getState().getInFlightQueries(host); if (inFlight > maxRequests) excessInflightQueriesSpotted.set(true); } }; openConnectionsWatcherExecutor.scheduleAtFixedRate( openConnectionsWatcher, 200, 200, TimeUnit.MILLISECONDS); // Generate the load for (int i = 0; i < 10000; i++) session.executeAsync("SELECT release_version FROM system.local"); openConnectionsWatcherExecutor.shutdownNow(); if (excessInflightQueriesSpotted.get()) { fail("Inflight queries exceeded the limit"); } }
@Override public void run() throws HiveException, ExampleException, IOException { try { hiveClient.authenticate(LOGIN, PASSWORD); HiveMessageHandler<DeviceNotification> notificationsHandler = new HiveMessageHandler<DeviceNotification>() { @Override public void handle(DeviceNotification notification) { print("Notification received: {}" + notification); } }; Timestamp serverTimestamp = hiveClient.getInfo().getServerTimestamp(); SubscriptionFilter notificationSubscriptionFilter = new SubscriptionFilter(null, null, serverTimestamp); hiveClient .getNotificationsController() .subscribeForNotifications(notificationSubscriptionFilter, notificationsHandler); ScheduledExecutorService commandsExecutor = Executors.newSingleThreadScheduledExecutor(); commandsExecutor.scheduleAtFixedRate(new CommandTask(), 3, 3, TimeUnit.SECONDS); Thread.currentThread().join(TimeUnit.SECONDS.toMillis(30)); commandsExecutor.shutdownNow(); } catch (InterruptedException e) { throw new ExampleException(e.getMessage(), e); } finally { hiveClient.close(); } }
/** Stop the decommission monitor thread, waiting briefly for it to terminate. */ void close() { executor.shutdownNow(); try { executor.awaitTermination(3000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } }
public void shutdown() { if (scheduledFuture != null) { scheduledFuture.cancel(false); scheduledFuture = null; } executorService.shutdownNow(); }
@Override protected void shutDown() throws Exception { if (scheduler != null) { scheduler.shutdownNow(); } super.shutDown(); }
@Test(timeout = 60000) public void testHeartbeatsKeepsConnectionOpen() throws Exception { String connectFrame = "STOMP\n" + "login:system\n" + "passcode:manager\n" + "accept-version:1.1\n" + "heart-beat:2000,0\n" + "host:localhost\n" + "\n" + Stomp.NULL; stompConnection.sendFrame(connectFrame); String f = stompConnection.receiveFrame(); assertTrue(f.startsWith("CONNECTED")); assertTrue(f.indexOf("version:1.1") >= 0); assertTrue(f.indexOf("heart-beat:") >= 0); assertTrue(f.indexOf("session:") >= 0); LOG.debug("Broker sent: " + f); String message = "SEND\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + Stomp.NULL; stompConnection.sendFrame(message); ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate( new Runnable() { @Override public void run() { try { LOG.info("Sending next KeepAlive"); stompConnection.keepAlive(); } catch (Exception e) { } } }, 1, 1, TimeUnit.SECONDS); TimeUnit.SECONDS.sleep(20); String frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "id:12345\n" + "ack:auto\n\n" + Stomp.NULL; stompConnection.sendFrame(frame); StompFrame stompFrame = stompConnection.receive(); assertTrue(stompFrame.getAction().equals("MESSAGE")); service.shutdownNow(); }
/** * This should be called when the server is shutting down, after stopping active requests if * possible. */ public void stopInternalRunner() { isRunning = false; logger.info("Stopping Commander and Runner Tasks"); scheduledFuture.cancel(false); scheduledExecutorService.shutdownNow(); threadPoolExecutor.shutdownNow(); networkTransaction.closeAll(false); }
/** Shutdown the ScheduledExecutorService. */ @Override protected void close() { // Cancel all remaining futures. for (CacheValues cvs : mResults.values()) if (cvs.mFuture != null) cvs.mFuture.cancel(true); // Shutdown the ScheduledExecutorService immediately. mScheduledExecutorService.shutdownNow(); }
/** Stop device found scheduled service */ private void stopDeviceFoundVerificationService() { if (scheduledService == null) { return; } Log.d(TAG, "Device: '" + deviceId + "' stops DeviceFoundVerification scheduled service"); scheduledService.shutdownNow(); scheduledService = null; } // stopDeviceFoundVerification
private void stopUpdating() { if (mUpdater != null && !mUpdater.isShutdown()) { mUpdater.shutdownNow(); mHandler = null; mUpdater = null; } }
@Deactivate public void deactivate() { executor.shutdownNow(); eventDispatcher.removeSink(WorkPartitionEvent.class); leadershipService.removeListener(leaderListener); log.info("Stopped"); }
@Override public List<Runnable> shutdownNow() { ArrayList<Runnable> result = new ArrayList<Runnable>(); for (ScheduledExecutorService w : workers) { result.addAll(w.shutdownNow()); } return result; }
@AfterClass public void tearDown() throws Exception { httpClient.close(); httpClient = null; executor.shutdownNow(); executor = null; }
public void close() throws IOException { if (!closed) { service.shutdownNow(); flush(); connection.getOutputStream().close(); connection.disconnect(); } closed = true; }
synchronized void shutdown() { stop(); executor.shutdown(); try { executor.awaitTermination(3, TimeUnit.SECONDS); } catch (InterruptedException e) { executor.shutdownNow(); } }
@Test public void testTumblingWindowUniqueElements() { final ScheduledExecutorService timerService = Executors.newSingleThreadScheduledExecutor(); try { final int windowSize = 50; final CollectingOutput<Tuple2<Integer, Integer>> out = new CollectingOutput<>(windowSize); AggregatingProcessingTimeWindowOperator<Integer, Tuple2<Integer, Integer>> op = new AggregatingProcessingTimeWindowOperator<>( sumFunction, fieldOneSelector, IntSerializer.INSTANCE, tupleSerializer, windowSize, windowSize); final Object lock = new Object(); final StreamTask<?, ?> mockTask = createMockTaskWithTimer(timerService, lock); op.setup(mockTask, new StreamConfig(new Configuration()), out); op.open(); final int numElements = 1000; for (int i = 0; i < numElements; i++) { synchronized (lock) { StreamRecord<Tuple2<Integer, Integer>> next = new StreamRecord<>(new Tuple2<>(i, i)); op.setKeyContextElement(next); op.processElement(next); } Thread.sleep(1); } out.waitForNElements(numElements, 60_000); // get and verify the result List<Tuple2<Integer, Integer>> result = out.getElements(); assertEquals(numElements, result.size()); synchronized (lock) { op.close(); } op.dispose(); Collections.sort(result, tupleComparator); for (int i = 0; i < numElements; i++) { assertEquals(i, result.get(i).f0.intValue()); assertEquals(i, result.get(i).f1.intValue()); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } finally { timerService.shutdownNow(); } }
public static void shutdown() { flush(); if (Debug.ENABLED) ((Wrapper) _executor).shutdown(); else { if (_executor instanceof ExecutorService) ((ExecutorService) _executor).shutdown(); } _scheduler.shutdownNow(); }
@Override public void close() { watermarkTimer.cancel(true); scheduleExecutor.shutdownNow(); // emit one last +Inf watermark to make downstream watermark processing work // when some sources close early synchronized (lockingObject) { output.emitWatermark(new Watermark(Long.MAX_VALUE)); } }
/** * Cancels the {@link SourcePollerRunner} thread that had been previously scheduled to run at * specific intervals. Invoked by the CatalogFramework's blueprint when the framework is * unregistered/uninstalled. * * @param framework unused, but required by blueprint * @param properties unused, but required by blueprint */ public void cancel(CatalogFramework framework, Map properties) { LOGGER.debug("Cancelling scheduled polling."); runner.shutdown(); handle.cancel(true); scheduler.shutdownNow(); }