Package java.util.concurrent

Examples of java.util.concurrent.ThreadFactory


 
  // background executor
  private ExecutorService backgroundExecutor;
 
  public CassandraService() {
    backgroundExecutor = Executors.newCachedThreadPool(new ThreadFactory() {
      private AtomicInteger idCounter = new AtomicInteger();
      @Override
      public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName("CassandraWebConsoleExecutor-" + idCounter.incrementAndGet());
View Full Code Here


            throw new IllegalArgumentException("defaultResurce must be > 0"); //$NON-NLS-1$
        }
        if (threadConfig == null) {
            throw new IllegalArgumentException("threadConfig must not be null"); //$NON-NLS-1$
        }
        this.defaultExecutor = Executors.newFixedThreadPool(defaultResuorce, new ThreadFactory() {
            private final AtomicInteger count = new AtomicInteger();
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(MessageFormat.format(
                        "ParallelJobScheduler-{0}",
                        String.valueOf(count.incrementAndGet())));
                return thread;
            }
        });
        HashMap<String, ExecutorService> map = new HashMap<String, ExecutorService>();
        for (Map.Entry<String, Integer> entry : threadConfig.entrySet()) {
            final String name = entry.getKey();
            Integer value = entry.getValue();
            if (value == null || value < 0) {
                throw new IllegalArgumentException(MessageFormat.format(
                        "thread config must be > 0: key={0}, value={1}",
                        name,
                        value));
            }
            map.put(name, Executors.newFixedThreadPool(value, new ThreadFactory() {
                private final AtomicInteger count = new AtomicInteger();
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setName(MessageFormat.format(
View Full Code Here

        }
    }

    private ExecutorService createJobflowExecutor(final String batchId) {
        assert batchId != null;
        ThreadFactory threadFactory = new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r);
                thread.setName(MessageFormat.format(
                        "JobflowExecutor-{0}",
View Full Code Here

      this.sharedState = state;
   }

   public void start() {
      this.flushThread = new FlushThread();
      this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
         @Override
         public Thread newThread(Runnable r) {
            Thread t = new Thread(Thread.currentThread().getThreadGroup(), r);
            t.setDaemon(true);
            t.setName("Flush Thread");
View Full Code Here

   *
   * @param prefix  The prefix of every created Thread's name
   * @return a {@link java.util.concurrent.ThreadFactory} that names threads
   */
  public static ThreadFactory getNamedThreadFactory(final String prefix) {
    return new ThreadFactory() {

      private final AtomicInteger threadNumber = new AtomicInteger(1);
     
      @Override
      public Thread newThread(Runnable r) {
View Full Code Here

    // there's files to split. It then fires up everything, waits for
    // completion and finally checks for any exception
    int nbFiles = hstoreFilesToSplit.size();
    ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    builder.setNameFormat("StoreFileSplitter-%1$d");
    ThreadFactory factory = builder.build();
    ThreadPoolExecutor threadPool =
      (ThreadPoolExecutor) Executors.newFixedThreadPool(nbFiles, factory);
    List<Future<Void>> futures = new ArrayList<Future<Void>>(nbFiles);

     // Split each store file.
View Full Code Here

    this.aclsManager = new JobACLsManager(conf);
    this.username = System.getProperty("user.name");
    this.jobACLs = aclsManager.constructJobACLs(conf);

    ThreadFactory threadFactory = new ThreadFactoryBuilder()
      .setNameFormat("Job Fail Wait Timeout Monitor #%d")
      .setDaemon(true)
      .build();
    this.executor = new ScheduledThreadPoolExecutor(1, threadFactory);
View Full Code Here

  }

  static ThreadPoolExecutor getOpenAndCloseThreadPool(int maxThreads,
      final String threadNamePrefix) {
    return Threads.getBoundedCachedThreadPool(maxThreads, 30L, TimeUnit.SECONDS,
      new ThreadFactory() {
        private int count = 1;

        public Thread newThread(Runnable r) {
          return new Thread(r, threadNamePrefix + "-" + count++);
        }
View Full Code Here

    final ThreadGroup threadGroup = new ThreadGroup(getClass().getSimpleName());
    // Create one ThreadPool per volume
    for (int v = 0 ; v < volumes.length; v++) {
      final File vol = volumes[v];
      ThreadFactory threadFactory = new ThreadFactory() {
          int counter = 0;

          @Override
          public Thread newThread(Runnable r) {
            int thisIndex;
View Full Code Here

     * This default spawns up to 32 background thread on an as need basis. Idle
     * threads are pruned after one minute.
     * @return  fresh ScheduledExecutorService
     */
    public static ScheduledExecutorService defaultScheduledExecutor() {
        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(32, new ThreadFactory() {
            private final AtomicInteger counter = new AtomicInteger();

            @Override
            public Thread newThread(Runnable r) {
                Thread thread = new Thread(r, createName());
View Full Code Here

TOP

Related Classes of java.util.concurrent.ThreadFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.