Shutdown executor in order.

@param iterator Executors to shutdown.
7441
private void shutdownGracefully(final Iterator<EventExecutorGroup> iterator) {
        if (iterator.hasNext()) {
            EventExecutorGroup group = iterator.next();
            if (!group.isShuttingDown()) {
                group.shutdownGracefully().addListener(future -> {
                    if (!future.isSuccess()) {
                        //log.debug("shutdown of {} resulted in exception", group, future.cause());
                    }
                    shutdownGracefully(iterator);
                });
            }
        }
    }
404701
public static void shutdownExecutor(ExecutorService executor, final String name)
    {
        executor.shutdown();
        try {
            log.info("Waiting for %s to shutdown", name);
            if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
                log.warn("%s did not shutdown properly", name);
            }
        }
        catch (InterruptedException e) {
            log.warn("Interrupted while waiting for %s to shutdown", name);
            Thread.currentThread().interrupt();
        }
    }
921259
private void destroyPingExecutor() {
        synchronized (pingExecutor) {
            if (!pingExecutor.isShutdown()) {
                try {
                    log.debugf("Shutting down WebSocket ping executor");
                    pingExecutor.shutdown();
                    if (!pingExecutor.awaitTermination(1, TimeUnit.SECONDS)) {
                        pingExecutor.shutdownNow();
                    }
                } catch (Throwable t) {
                    log.warnf("Cannot shut down WebSocket ping executor. Cause=%s", t.toString());
                }
            }
        }
    }
1058001
@Override
    public void stop() throws InterruptedException, Exception {
        executor.shutdown();
        final boolean success = executor.awaitTermination(shutdownPeriod.getQuantity(), shutdownPeriod.getUnit());
        if (!success && LOG.isDebugEnabled()) {
            LOG.debug("Timeout has elapsed before termination completed for executor " + executor.toString());
        }
    }
839187
@Override
	public void shutdown() {
		if (collection != null) {
			try {
				collection.shutdown();
			} catch (IOException e) {
				LOGGER.severe("FAILED collection shutdown" + e.getMessage());
			}
		}
		if (exclusionFactory != null) {
			exclusionFactory.shutdown();
		}
	}
944291
public synchronized void shutdown() {
        this.shutdownManagementWatchdogs();

        // deactivate all Watchdogs ....
        Iterator iter = registeredWachdogs.values().iterator();
        while (iter.hasNext()) {
            IWatchdog th = (IWatchdog) iter.next();
            th.deactivate();
            if (log.isInfoEnabled()) {
                log.info(". . . Deactivating Watchdog " + th.getId());
            }
        }

        this.kill();

    }
1364367
public synchronized void shutdownTaskScheduler(){
        if (scheduler != null && !scheduler.isShutdown()) {
            scheduler.shutdown();
            logger.info("shutdowned the task scheduler. No longer accepting new tasks");
            scheduler = null;
        }
    }
684520
@Override
    public void shutdown() {
        synchronized (connections) {
            parent.channelCloses(this);
            for (final MessageInbound connection : connections) {
                try {
                    connection.getWsOutbound().close(0, null);
                } catch (final IOException e) {
                    LOG.error("Connection [" + connection.toString() + "] can't be closed.", e);
                } finally {
                    final ExecutorService executorService = connectionThreads.get(connection);
                    if (executorService != null) {
                        executorService.shutdown();
                    }
                    connectionThreads.remove(connection);
                }
            }
            connections.clear();
        }
        callback = null;
    }
1327885
public final synchronized void shutdown() {  // synchronize on 'this' to avoid races with registerStreams
        stopped = true;
        // If the cleanup task is running tell it to stop looping, and then remove it from the scheduled executor
        if (cleanupTaskFuture != null) {
            cleanupTaskFuture.cancel(false);
        }

        // Close remaining streams
        for (Map.Entry<InputStreamKey, TimedStreamEntry> entry : streamMap.entrySet()) {
            InputStreamKey key = entry.getKey();
            TimedStreamEntry timedStreamEntry = entry.getValue();
            //noinspection SynchronizationOnLocalVariableOrMethodParameter
            synchronized (timedStreamEntry) { // ensure there's no race with a request that got a ref before we removed it
                closeStreamEntry(timedStreamEntry, key.requestId, key.index);
            }
        }
    }
235819
public void shutdown() {
		synchronized (lock) {
			// first shutdown the thread pool
			ScheduledExecutorService es = this.executorService;
			if (es != null) {
				es.shutdown();
				try {
					es.awaitTermination(cleanupInterval, TimeUnit.MILLISECONDS);
				}
				catch (InterruptedException e) {
					// may happen
				}
			}

			entries.clear();
			jobRefHolders.clear();

			// clean up the all storage directories
			for (File dir : storageDirectories) {
				try {
					FileUtils.deleteDirectory(dir);
					LOG.info("removed file cache directory {}", dir.getAbsolutePath());
				}
				catch (IOException e) {
					LOG.error("File cache could not properly clean up storage directory: {}", dir.getAbsolutePath(), e);
				}
			}

			// Remove shutdown hook to prevent resource leaks
			ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
		}
	}
1088782
public void shutdown() {
        if (_producer != null) {
            _producer.close();
        }
        _executorService.shutdown();
        try {
            if (!_executorService.awaitTermination(10, TimeUnit.SECONDS)) {
                _logger.warn("Shutdown of Kafka executor service timed out after 10 seconds.");
                _executorService.shutdownNow();
            }
        } catch (InterruptedException ex) {
            _logger.warn("Shutdown of executor service was interrupted.");
            Thread.currentThread().interrupt();
        }
    }
1205332
public static synchronized void shutdown()
    {
        if( c_factories == null ) return; // Nothing to do

        for( Iterator<Entry<String, StopWatchFactory>> i = c_factories.entrySet().iterator(); i.hasNext() ; )
        {
            Map.Entry<String,StopWatchFactory> e = i.next();

            StopWatchFactory swf = e.getValue();
            swf.internalShutdown();

            i.remove();
        }

        c_factories = null;
    }
671317
def shutdown(self):
		
		with self.lock:
			self.pool.inqueue.put(StopIteration)   # Stop the pool workers
			self.waitqueue.put(StopIteration)      # Stop the input_feeder
			_iterqueue(self.waitqueue) >> item[-1] # Exhaust the waitqueue
			self.closed = True
		self.join()
272644
public synchronized void shutdown() {
    if (!isActive) {
      return;
    }
    log.info("Shutting down the default async job executor [{}].", getClass().getName());
    
    if (timerJobRunnable != null) {
      timerJobRunnable.stop();
    }
    if (asyncJobsDueRunnable != null) {
      asyncJobsDueRunnable.stop();
    }
    if (resetExpiredJobsRunnable != null) {
      resetExpiredJobsRunnable.stop();
    }
    
    stopResetExpiredJobsThread();
    stopTimerAcquisitionThread();
    stopJobAcquisitionThread();
    stopExecutingAsyncJobs();

    timerJobRunnable = null;
    asyncJobsDueRunnable = null;
    resetExpiredJobsRunnable = null;
    
    isActive = false;
  }
802482
public static <T> Iterator<T> readOnly(final Iterator<T> itr) {
        return new Iterator<T>() {
            public boolean hasNext() {
                return itr.hasNext();
            }

            public T next() {
                return itr.next();
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
18553
@Override
    public void close()
    {
        isOpen.set(false);
        Iterator<Future<?>> iterator = futures.iterator();
        while ( iterator.hasNext() )
        {
            Future<?> future = iterator.next();
            iterator.remove();
            if ( !future.isDone() && !future.isCancelled() && !future.cancel(true) )
            {
                log.warn("Could not cancel " + future);
            }
        }
        if (shutdownOnClose) {
            executorService.shutdownNow();
        }
    }
1320304
public void shutdown ()
    {
        if (_self == null) { // never initialized
            return;
        }

        // clear out our invocation service
        if (_nodeobj != null) {
            _invmgr.clearDispatcher(_nodeobj.peerService);
        }

        // clear out our client observer registration
        _clmgr.removeClientObserver(this);

        // clear our record from the node table
        if (!_adHoc) {
            _invoker.postUnit(new WriteOnlyUnit("shutdownNode(" + _nodeName + ")") {
                @Override
                public void invokePersist () throws Exception {
                    _noderepo.shutdownNode(_nodeName);
                }
            });
        }

        // shut down the peers
        for (PeerNode peer : _peers.values()) {
            peer.shutdown();
        }
    }