Exemplo n.º 1
0
 private static void keepAliveThreads(ThreadPoolExecutor e, AtmosphereConfig config) {
   int keepAlive = DEFAULT_KEEP_ALIVE;
   String s = config.getInitParameter(ApplicationConfig.EXECUTORFACTORY_KEEP_ALIVE);
   if (s != null) {
     keepAlive = Integer.parseInt(s);
   }
   e.setKeepAliveTime(keepAlive, TimeUnit.SECONDS);
 }
Exemplo n.º 2
0
 /**
  * Creates a new {@link ThreadPoolExecutor} ready to carry out work. All pools are pre-started by
  * default and will terminate after not receiving work for the argued timeout value.
  *
  * @param poolName the name of this thread pool.
  * @param poolSize the size of this thread pool.
  * @param poolPriority the priority of this thread pool.
  * @param timeout how long in minutes it takes for threads in this pool to timeout.
  * @return the newly constructed thread pool.
  */
 public static ThreadPoolExecutor createThreadPool(
     String poolName, int poolSize, int poolPriority, long timeout) {
   ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(poolSize);
   threadPool.setThreadFactory(new ThreadProvider(poolName, poolPriority, true));
   threadPool.setRejectedExecutionHandler(new ThreadPoolRejectedExecutionHook());
   threadPool.setKeepAliveTime(timeout, TimeUnit.MINUTES);
   threadPool.allowCoreThreadTimeOut(true);
   threadPool.prestartAllCoreThreads();
   return threadPool;
 }
 private void configure(final String name) {
   /*
    * All executors should be shutdown on application shutdown.
    */
   ShutdownHookManager.register(shutdownHook);
   /*
    * All threads should stop after 60 seconds of idle time
    */
   delegate.setKeepAliveTime(
       FIXED_THREAD_KEEPALIVE_TIMEOUT.longValue(), FIXED_THREAD_KEEPALIVE_TIMEOUT.getTimeUnit());
   /*
    * Fixes non starting with corepoolsize von 0 and not filled queue (Java Conurrency In Practice Chapter 8.3.1).
    * If this bug can occur, a exception would be thrown here.
    */
   delegate.allowCoreThreadTimeOut(true);
   /*
    * Named threads improve debugging.
    */
   delegate.setThreadFactory(new WrappedThreadFactory(name, delegate.getThreadFactory()));
 }
 public void setMaxIdleTime(int maxIdleTime) {
   this.maxIdleTime = maxIdleTime;
   if (executor != null) {
     executor.setKeepAliveTime(maxIdleTime, TimeUnit.MILLISECONDS);
   }
 }
Exemplo n.º 5
0
 public void setKeepAliveTime(long time) {
   pool.setKeepAliveTime(time, TimeUnit.MILLISECONDS);
 }