java.util.concurrent.ThreadPoolExecutor.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中java.util.concurrent.ThreadPoolExecutor.<init>()方法的一些代码示例,展示了ThreadPoolExecutor.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.<init>()方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:<init>

ThreadPoolExecutor.<init>介绍

[英]Creates a new ThreadPoolExecutor with the given initial parameters and default thread factory and rejected execution handler. It may be more convenient to use one of the Executors factory methods instead of this general purpose constructor.
[中]使用给定的初始参数、默认线程工厂和被拒绝的执行处理程序创建新的ThreadPoolExecutor。使用一种Executors工厂方法而不是这个通用构造函数可能更方便。

代码示例

代码示例来源:origin: stackoverflow.com

public static ExecutorService newFixedThreadPool(int nThreads) {
   return new ThreadPoolExecutor(nThreads, nThreads,
                  0L, TimeUnit.MILLISECONDS,
                  new LinkedBlockingQueue<Runnable>());
 }

public static ExecutorService newCachedThreadPool() {
  return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                 60L, TimeUnit.SECONDS,
                 new SynchronousQueue<Runnable>());
}

代码示例来源:origin: spring-projects/spring-framework

executor = new ThreadPoolExecutor(
    this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
    queue, threadFactory, rejectedExecutionHandler) {
executor = new ThreadPoolExecutor(
    this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
    queue, threadFactory, rejectedExecutionHandler);
executor.allowCoreThreadTimeOut(true);

代码示例来源:origin: stackoverflow.com

BlockingQueue<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<Runnable>(
  100);
ExecutorService executorService = new ThreadPoolExecutor(1, 10, 30,
  TimeUnit.SECONDS, linkedBlockingDeque,
  new ThreadPoolExecutor.CallerRunsPolicy());

代码示例来源:origin: apache/activemq

private ThreadPoolExecutor createExecutor() {
    ThreadPoolExecutor exec = new ThreadPoolExecutor(0, 2, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), factory);
    exec.allowCoreThreadTimeOut(true);
    return exec;
  }
}

代码示例来源:origin: thinkaurelius/titan

private static ExecutorService getDefaultExecutor() {
    return new ThreadPoolExecutor(0, 1, KEEPALIVE_TIME, KEEPALIVE_UNIT, new LinkedBlockingQueue<Runnable>(), THREAD_FACTORY);
  }
}

代码示例来源:origin: apache/hbase

/**
 * Create a new CachedThreadPool with a bounded number as the maximum
 * thread size in the pool.
 *
 * @param maxCachedThread the maximum thread could be created in the pool
 * @param timeout the maximum time to wait
 * @param unit the time unit of the timeout argument
 * @param threadFactory the factory to use when creating new threads
 * @return threadPoolExecutor the cachedThreadPool with a bounded number
 * as the maximum thread size in the pool.
 */
public static ThreadPoolExecutor getBoundedCachedThreadPool(
  int maxCachedThread, long timeout, TimeUnit unit,
  ThreadFactory threadFactory) {
 ThreadPoolExecutor boundedCachedThreadPool =
  new ThreadPoolExecutor(maxCachedThread, maxCachedThread, timeout,
   unit, new LinkedBlockingQueue<>(), threadFactory);
 // allow the core pool threads timeout and terminate
 boundedCachedThreadPool.allowCoreThreadTimeOut(true);
 return boundedCachedThreadPool;
}

代码示例来源:origin: Justson/AgentWeb

private void internalInit() {
  if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) {
    mThreadPoolExecutor.shutdownNow();
  }
  mThreadPoolExecutor = new ThreadPoolExecutor(
      CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
      sPoolWorkQueue, sThreadFactory);
  mThreadPoolExecutor.allowCoreThreadTimeOut(true);
}

代码示例来源:origin: stackoverflow.com

public class ImageManager {
  BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(blockQueueSize);
  RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
  private ExecutorService executorService =  new ThreadPoolExecutor(numOfThread, numOfThread, 
    0L, TimeUnit.MILLISECONDS, blockingQueue, rejectedExecutionHandler);

  private int downloadThumbnail(String fileListPath){
    executorService.submit(new yourRunnable());
  }
}

代码示例来源:origin: stackoverflow.com

public static ExecutorService newFixedThreadPool(int nThreads) {
  return new ThreadPoolExecutor(nThreads, nThreads,
                 0L, TimeUnit.MILLISECONDS,
                 new LinkedBlockingQueue<Runnable>());
}

代码示例来源:origin: apache/geode

public static ExecutorService newFixedThreadPoolWithFeedSize(String threadName,
  int poolSize, int feedSize) {
 LinkedBlockingQueue<Runnable> feed = new LinkedBlockingQueue<>(feedSize);
 RejectedExecutionHandler rejectionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
 ThreadFactory threadFactory = new LoggingThreadFactory(threadName);
 ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSize, poolSize, 10, SECONDS, feed,
   threadFactory, rejectionHandler);
 executor.allowCoreThreadTimeOut(true);
 return executor;
}

代码示例来源:origin: apache/activemq

private ThreadPoolExecutor createExecutor() {
  ThreadPoolExecutor exec = new ThreadPoolExecutor(0, Integer.MAX_VALUE, getDefaultKeepAliveTime(), TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), factory);
  exec.allowCoreThreadTimeOut(true);
  return exec;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Create a scheduler that executes tasks in dynamically adjustable intervals
 */
public TimeScheduler3() {
  pool=new ThreadPoolExecutor(4, 10,
                30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(100),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
  start();
}

代码示例来源:origin: springside/springside4

public ThreadPoolExecutor build() {
    BlockingQueue<Runnable> queue = null;
    if (queueSize < 1) {
      queue = new LinkedBlockingQueue<Runnable>();
    } else {
      queue = new ArrayBlockingQueue<Runnable>(queueSize);
    }
    threadFactory = createThreadFactory(threadFactory, threadNamePrefix, daemon);
    if (rejectHandler == null) {
      rejectHandler = defaultRejectHandler;
    }
    return new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.MILLISECONDS, queue, threadFactory,
        rejectHandler);
  }
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates a new instance of {@link AsyncUfsAbsentPathCache}.
 *
 * @param mountTable the mount table
 * @param numThreads the maximum number of threads for the async thread pool
 */
public AsyncUfsAbsentPathCache(MountTable mountTable, int numThreads) {
 mMountTable = mountTable;
 mCurrentPaths = new ConcurrentHashMap<>(8, 0.95f, 8);
 mCache = CacheBuilder.newBuilder().maximumSize(MAX_PATHS).build();
 mThreads = numThreads;
 mPool = new ThreadPoolExecutor(mThreads, mThreads, THREAD_KEEP_ALIVE_SECONDS,
   TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
   ThreadFactoryUtils.build("UFS-Absent-Path-Cache-%d", true));
 mPool.allowCoreThreadTimeOut(true);
}

代码示例来源:origin: apache/zookeeper

this.connectionExecutor = new ThreadPoolExecutor(3,
    quorumCnxnThreadsSize, 60, TimeUnit.SECONDS,
    new SynchronousQueue<Runnable>(), daemonThFactory);
this.connectionExecutor.allowCoreThreadTimeOut(true);

代码示例来源:origin: wildfly/wildfly

@ManagedOperation
public void start() throws IOException, MalformedObjectNameException, MBeanRegistrationException {
  srv_sock=new ServerSocket(port, 50, bind_addr);
  if(thread_pool == null) {
    thread_pool=new ThreadPoolExecutor(core_threads, max_threads, idle_time, TimeUnit.MILLISECONDS,
                      new SynchronousQueue<>(), new ThreadPoolExecutor.CallerRunsPolicy());
    // thread_pool=new DirectExecutor();
  }
  if(thread == null || !thread.isAlive()) {
    thread=new Thread(this, "Acceptor");
    thread.start();
  }
  start_time=System.currentTimeMillis();
}

代码示例来源:origin: oblac/jodd

public void start() {
  executorService = new ThreadPoolExecutor(
    corePoolSize,
    maximumPoolSize,
    keepAliveTimeMillis,
    TimeUnit.MILLISECONDS,
    new LinkedBlockingQueue<>(queueCapacity));
}

代码示例来源:origin: SonarSource/sonarqube

private static ThreadPoolExecutor createDelegate() {
 ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
  MAX_THREAD_COUNT, MAX_THREAD_COUNT,
  KEEP_ALIVE_TIME_IN_MINUTES, MINUTES,
  new LinkedBlockingQueue<>(UNLIMITED_QUEUE),
  new ThreadFactoryBuilder()
   .setDaemon(false)
   .setNameFormat("SQ_async-%d")
   .setUncaughtExceptionHandler(((t, e) -> LOG.error("Thread " + t + " failed unexpectedly", e)))
   .build());
 threadPoolExecutor.allowCoreThreadTimeOut(true);
 return threadPoolExecutor;
}

代码示例来源:origin: wildfly/wildfly

public AsyncNoBundler() {
  thread_pool=new ThreadPoolExecutor(0, max_threads,
                    30000, TimeUnit.MICROSECONDS,
                    new SynchronousQueue<>(),
                    new DefaultThreadFactory("async-bundler", true, true),
                    new ThreadPoolExecutor.CallerRunsPolicy());
  thread_pool.allowCoreThreadTimeOut(true);
}

代码示例来源:origin: apache/hbase

@Override
public void start() {
 LOG.info("Using {} as user call queue; handlerCount={}; maxQueueLength={}",
  this.getClass().getSimpleName(), handlerCount, maxQueueLength);
 this.executor = new ThreadPoolExecutor(
   handlerCount,
   handlerCount,
   60,
   TimeUnit.SECONDS,
   new ArrayBlockingQueue<>(maxQueueLength),
   new DaemonThreadFactory("FifoRpcScheduler.handler"),
   new ThreadPoolExecutor.CallerRunsPolicy());
}

相关文章

ThreadPoolExecutor类方法