View Javadoc

1   package org.lsst.ccs.utilities.dispatch;
2   
3   
4   import java.util.concurrent.ExecutorService;
5   import java.util.concurrent.Executors;
6   import java.util.concurrent.ThreadFactory;
7   import java.util.concurrent.atomic.AtomicInteger;
8   import java.util.logging.Logger;
9   
10  /**
11   * @author bernard AMADE
12   */
13  
14  class PackCst {
15      public static final Logger CURLOG = Logger.getLogger(PackCst.class.getPackage().getName()) ;
16  
17      static AtomicInteger threadCount = new AtomicInteger() ;
18      /**
19       * All objects of this package may use the same Thread Pool.
20       * (The Cached Thread Pool may be changed to fixed size)
21       * <P>
22       *     All Threads created here should be Daemons (has be changed)
23       */
24      static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool(new ThreadFactory() {
25          @Override
26          public Thread newThread(Runnable runnable) {
27              Thread thread = new Thread(runnable, "Dispatcher-"+ threadCount.incrementAndGet());
28              thread.setDaemon(true);
29              return thread;
30          }
31      });
32  
33      static final ExecutorService SINGLE_THREAD = Executors.newSingleThreadExecutor(new ThreadFactory() {
34          @Override
35          public Thread newThread(Runnable runnable) {
36              Thread thread = new Thread(runnable, "SingleDispatcher-"+ threadCount.incrementAndGet());
37              thread.setDaemon(true);
38              return thread;
39          }
40      });
41  }