Sets thread pool to any given {@link ThreadPoolExecutor} to allow use of an alternative execution style.

@param pool thread pool to share
334558
public static void setThreadPool(ThreadPoolExecutor pool) {
		if (ConcurrencyTools.pool != pool) {
			shutdown();
			ConcurrencyTools.pool = pool;
		}
	}
1077528
public void setShortRunningThreadPool(BlockingExecutor executor)
   {
      if (trace)
         log.trace("short running executor:" + (executor != null ? executor.getClass() : "null"));

      if (executor != null)
      {
         if (executor instanceof StatisticsExecutor)
         {
            this.shortRunningExecutor = (StatisticsExecutor) executor;
         }
         else
         {
            this.shortRunningExecutor = new StatisticsExecutorImpl(executor);
         }
      }
   }
1253210
protected void startQueue(GerritWorkersConfig config) {
        if (executor == null) {
            logger.debug("Starting the sending thread pool.");
            executor = new ThreadPoolExecutor(
                    config.getNumberOfSendingWorkerThreads(),
                    config.getNumberOfSendingWorkerThreads(),
                    THREAD_KEEP_ALIVE_TIME, TimeUnit.MINUTES,
                    new LinkedBlockingQueue<Runnable>(),
                    new ThreadFactory() {
                        private final ThreadFactory parent = Executors.defaultThreadFactory();
                        private final AtomicInteger tid = new AtomicInteger(1);

                        @Override
                        public Thread newThread(final Runnable task) {
                          final Thread t = parent.newThread(task);
                          t.setName(THREAD_PREFIX + tid.getAndIncrement());
                          return t;
                        }
                      });
            executor.allowCoreThreadTimeOut(true);
            //Start with one thread, and build it up gradually as it needs.
            executor.prestartCoreThread();
            logger.info("SendQueue started! Current pool size: {}", executor.getPoolSize());
        } else {
            if (executor.getCorePoolSize() < config.getNumberOfSendingWorkerThreads()) {
                //If the number has increased we need to set the max first, or we'll get an IllegalArgumentException
                executor.setMaximumPoolSize(config.getNumberOfSendingWorkerThreads());
                executor.setCorePoolSize(config.getNumberOfSendingWorkerThreads());
            } else if (executor.getCorePoolSize() > config.getNumberOfSendingWorkerThreads()) {
                //If the number has decreased we need to set the core first.
                executor.setCorePoolSize(config.getNumberOfSendingWorkerThreads());
                executor.setMaximumPoolSize(config.getNumberOfSendingWorkerThreads());
            }
            logger.debug("SendQueue running. Current pool size: {}. Current Queue size: {}",
                    executor.getPoolSize(), getQueueSize());
            logger.debug("Nr of active pool-threads: {}", executor.getActiveCount());
        }
    }
1269274
public void setExecutorTaskMax(int max)
  {
    if (getThreadMax() < max)
      throw new ConfigException(L.l("<thread-executor-max> ({0}) must be less than <thread-max> ({1})",
                                    max, getThreadMax()));

    if (max == 0)
      throw new ConfigException(L.l("<thread-executor-max> must not be zero."));

    _executorTaskMax = max;
  }
482262
boolean manageIdlePool(ThreadPoolExecutor threadPool, long intervalCompleted) {

        // Manage the intervalCompleted count
        if (intervalCompleted == 0 && threadPool.getActiveCount() == 0) {
            consecutiveIdleCount++;
        } else {
            consecutiveIdleCount = 0;
        }

        if (consecutiveIdleCount >= IDLE_INTERVALS_BEFORE_PAUSE) {
            pause();
            lastAction = LastAction.PAUSE;
            return true;
        }

        return false;
    }
1116887
public static ExecutorService newSingleThreadPoolExecutor() {
        ExecutorService singleThreadPoolExecutor = Executors.newSingleThreadExecutor();
        EXECUTORS.add(singleThreadPoolExecutor);
        return singleThreadPoolExecutor;
    }
899032
public static ThreadPoolExecutorFactoryBean newThreadPoolExecutorFactoryBean(final ConnectionPoolingProperties config) {
        val bean = new ThreadPoolExecutorFactoryBean();
        bean.setMaxPoolSize(config.getMaxSize());
        bean.setCorePoolSize(config.getMinSize());
        return bean;
    }
71188
protected ExecutorService initializeExecutor(ThreadFactory threadFactory,
            RejectedExecutionHandler rejectedExecutionHandler) {
        this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
        if (this.removeOnCancelPolicy) {
            if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
                ((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
            } else {
                // logger.info("Could not apply remove-on-cancel policy - not a Java 7+ ScheduledThreadPoolExecutor");
            }
        }
        return this.scheduledExecutor;
    }
383170
public static ThreadPoolExecutor newCachedThreadPool(int corePoolSize,
                                                         int maximumPoolSize,
                                                         BlockingQueue<Runnable> queue) {
        return new ThreadPoolExecutor(corePoolSize,
            maximumPoolSize,
            DateUtils.MILLISECONDS_PER_MINUTE,
            TimeUnit.MILLISECONDS,
            queue);
    }
1102703
public synchronized boolean addPool(HostConnectionPool<CL> pool) {
        if (this.pools.add(pool)) {
            refresh();
            return true;
        }
        return false;
    }
747433
public static void init(Context contextValue, ExecutorService service) {
		context = contextValue;

		if (service == null) {
			executerService = Executors.newFixedThreadPool(THREAD_POOL_SIZE_DEFAULT);
		} else {
			executerService = service;
		}

	}
709483
public void setPoolSize(int poolSize) {
        // Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
        this.poolSize = poolSize;
        if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
            ((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
        }
    }
742906
private static void shutdown(ExecutorService executorService) {
        executorService.shutdown();
        try {
            if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
                executorService.shutdownNow();
                if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
                    System.err.println("Thread pool did not terminate");
                }
            }
        } catch (InterruptedException ie) {
            executorService.shutdownNow();
            Thread.currentThread().interrupt();
        }
    }
1273121
public static ThreadFactory threadFactory(final String alias) {
    return new ThreadFactory() {
      private final ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
      private final AtomicInteger threadCount = new AtomicInteger();
      private final String poolAlias = (alias == null ? "_default_" : alias);

      @Override
      public Thread newThread(Runnable r) {
        Thread t = new Thread(threadGroup, r, "Ehcache [" + poolAlias + "]-" + threadCount.getAndIncrement());
        if(DEBUG) {
          threads.put(System.identityHashCode(t), new Exception(t.getName()));
        }
        return t;
      }
    };
  }
716605
public void afterPropertiesSet() throws Exception {
        scheduler = new ScheduledThreadPoolExecutor(DEFAULT_POOL, new NamedThreadFactory("Otter-Statistics-Client"),
                                                    new ThreadPoolExecutor.CallerRunsPolicy());
        scheduler.submit(new Runnable() {

            public void run() {
                doSendDelayCountEvent();
            }
        });
    }
737905
ThreadPoolExecutor createChannelExecutor(String channel, final String threadPrefix, final int workerCount, int queueSize) {
		ThreadFactory threadFactory = new ThreadFactory() {
			private int counter = 0;
			@Override
			public Thread newThread(Runnable runnable) {
				return new Thread(runnable, threadPrefix + "-" + ++counter);
			}
		};
		ThreadPoolExecutor executor = new ChannelThreadPoolExecutor(channel, workerCount,
				new LinkedBlockingQueue<Runnable>(queueSize), threadFactory);
		return executor;
	}
567984
public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize) {
        return new ThreadPoolExecutor(corePoolSize,
            corePoolSize,
            0,
            TimeUnit.MILLISECONDS,
            new SynchronousQueue<Runnable>());
    }