类java.util.concurrent.RejectedExecutionHandler源码实例Demo

下面列出了怎么用java.util.concurrent.RejectedExecutionHandler的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Bats   文件: DefaultApexPluginDispatcher.java
@Override
protected void serviceInit(Configuration conf) throws Exception
{
  super.serviceInit(conf);
  LOG.debug("Creating plugin dispatch queue with size {}", QUEUE_SIZE);
  blockingQueue = new ArrayBlockingQueue<>(QUEUE_SIZE);
  RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler()
  {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
    {
      try {
        blockingQueue.remove();
        executor.submit(r);
      } catch (NoSuchElementException ex) {
        // Ignore no-such element as queue may finish, while this handler is called.
      }
    }
  };

  executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
      blockingQueue, new NameableThreadFactory("PluginExecutorThread", true), rejectionHandler);
}
 
@Test
@SuppressWarnings("serial")
public void testSettingRejectedExecutionHandlerToNullForcesUseOfDefaultButIsOtherwiseCool() throws Exception {
	ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
		@Override
		protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
			assertNotNull("Bah; the setRejectedExecutionHandler(..) method must use a default RejectedExecutionHandler if a null arg is passed in.");
			return super.createExecutor(poolSize, threadFactory, rejectedExecutionHandler);
		}
	};
	factory.setScheduledExecutorTasks(new ScheduledExecutorTask[]{
		new NoOpScheduledExecutorTask()
	});
	factory.setRejectedExecutionHandler(null); // the null must not propagate
	factory.afterPropertiesSet();
	factory.destroy();
}
 
源代码3 项目: deep-spark   文件: Utils.java
/**
 * Returns an instance of ThreadPoolExecutor using an bounded queue and blocking when the worker queue is full.
 * @param nThreads thread pool size
 * @param queueSize workers queue size
 * @return thread pool executor
 */
public static ExecutorService newBlockingFixedThreadPoolExecutor(int nThreads, int queueSize) {
    BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(queueSize);
    RejectedExecutionHandler blockingRejectedExecutionHandler = new RejectedExecutionHandler() {
        @Override
        public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
            try {
                executor.getQueue().put(task);
            } catch (InterruptedException e) {
            }
        }

    };

    return new ThreadPoolExecutor(nThreads, nThreads,
            0L, TimeUnit.MILLISECONDS, blockingQueue,
            blockingRejectedExecutionHandler);
}
 
源代码4 项目: ThreadDebugger   文件: RealExecutors.java
public ExceedCallImmediatelyExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                                     TimeUnit unit, String prefixName) {

    super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
            new SynchronousQueue<Runnable>(true),
            new RejectedExecutionHandler() {
                @Override
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    if (!executor.isShutdown()) {
                        TEMPORARY_CACHED_THREAD_POOL.
                                execute(((RealExecutor) executor).getCommandNameMap().get(r),
                                        r);
                    }
                }
            }, prefixName);
}
 
@Override
public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) {
    RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler();
    if (rejectedExecutionHandler == null) {
        rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
    }

    ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor(
        profile.getPoolSize(), managedThreadFactory, rejectedExecutionHandler);

    if (profile.getMaxPoolSize() > 0) {
        return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize());
    } else {
        return answer;
    }
}
 
源代码6 项目: Zebra   文件: Cpt7_Executor.java
public static void testThreadPoolExecutor(){
		BlockingQueue<Runnable> bq=new ArrayBlockingQueue<Runnable>(10);
		//在调用shutdown方法后,抛出RejectedExecutionException的异常
		//handler仅影响在执行shutdown后提交任务的响应情况
		RejectedExecutionHandler handler=new ThreadPoolExecutor.AbortPolicy();	//默认就是使用该机制
		//尽量不要自己创建线程工厂,除非有特殊的需求并且非常的了解线程池的工作机制,或者需要自己的管理机制
		//如果不传递默认线程工厂参数,则使用Executors.DefaultThreadFactory
		//了解Executors.DefaultThreadFactory的实现
		ThreadFactory tf=new MyThreadFactory();
		
 		//线程池中存在10个线程,最大允许20个线程,比10个多的线程在2秒钟内,没接到任务,就会自动消除
		//使用DelayQueue作为任务队列,超出线程范围时,采用拒绝处理的政策
		ThreadPoolExecutor tpe=new ThreadPoolExecutor(10, 20, 2, TimeUnit.SECONDS, bq, tf,handler);
//		int count=0;
		for(int i=0;i<23;i++){
			tpe.execute(new RunEntity());
			System.out.println("add"+i+"========");
		}
		tpe.shutdown();
	}
 
源代码7 项目: lams   文件: ThreadPoolExecutorFactoryBean.java
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = createExecutor(this.corePoolSize, this.maxPoolSize,
			this.keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

	// Wrap executor with an unconfigurable decorator.
	this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
			Executors.unconfigurableExecutorService(executor) : executor);

	return executor;
}
 
@Override
public ScheduledExecutorService createExecutor(int poolSize,
		ThreadFactory threadFactory,
		RejectedExecutionHandler rejectedExecutionHandler) {
	ScheduledExecutorService executorService = (ScheduledExecutorService) ReflectionUtils
			.invokeMethod(this.createExecutor, this.delegate, poolSize,
					traceThreadFactory(threadFactory), rejectedExecutionHandler);
	if (executorService instanceof TraceableScheduledExecutorService) {
		return executorService;
	}
	return new TraceableScheduledExecutorService(this.beanFactory, executorService);
}
 
源代码9 项目: pinpoint   文件: ExecutorFactoryBean.java
@Override
protected ThreadPoolExecutor createExecutor(
        int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
        ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

    final ThreadPoolExecutor threadPoolExecutor = newThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
    if (preStartAllCoreThreads) {
        threadPoolExecutor.prestartAllCoreThreads();
    }
    return threadPoolExecutor;
}
 
/**
 * A thread pool that that blocks clients submitting additional tasks if
 * there are already {@code activeTasks} running threads and {@code
 * waitingTasks} tasks waiting in its queue.
 *
 * @param activeTasks maximum number of active tasks
 * @param waitingTasks maximum number of waiting tasks
 * @param keepAliveTime time until threads are cleaned up in {@code unit}
 * @param unit time unit
 * @param prefixName prefix of name for threads
 */
public static BlockingThreadPoolExecutorService newInstance(
    int activeTasks,
    int waitingTasks,
    long keepAliveTime, TimeUnit unit,
    String prefixName) {

  /* Although we generally only expect up to waitingTasks tasks in the
  queue, we need to be able to buffer all tasks in case dequeueing is
  slower than enqueueing. */
  final BlockingQueue<Runnable> workQueue =
      new LinkedBlockingQueue<>(waitingTasks + activeTasks);
  ThreadPoolExecutor eventProcessingExecutor =
      new ThreadPoolExecutor(activeTasks, activeTasks, keepAliveTime, unit,
          workQueue, newDaemonThreadFactory(prefixName),
            new RejectedExecutionHandler() {
        @Override
        public void rejectedExecution(Runnable r,
            ThreadPoolExecutor executor) {
          //This is not expected to happen.
          LOG.error("Could not submit task to executor {}", executor.toString());
        }
      });
  eventProcessingExecutor.allowCoreThreadTimeOut(true);
  return new BlockingThreadPoolExecutorService(waitingTasks + activeTasks,
      eventProcessingExecutor);
}
 
源代码11 项目: gemfirexd-oss   文件: PooledExecutorWithDMStats.java
/** 
   * Create a new pool
   **/
  public PooledExecutorWithDMStats(BlockingQueue<Runnable> q, int maxPoolSize, PoolStatHelper stats, ThreadFactory tf, int msTimeout, RejectedExecutionHandler reh) {
    super(getCorePoolSize(maxPoolSize), maxPoolSize,
          msTimeout, TimeUnit.MILLISECONDS,
          q, tf, reh);
//     if (getCorePoolSize() != 0 && getCorePoolSize() == getMaximumPoolSize()) {
//       allowCoreThreadTimeOut(true); // deadcoded for 1.5
//     }
    this.stats = stats;
  }
 
源代码12 项目: dubbo-2.6.5   文件: EagerThreadPoolTest.java
@Test
public void getExecutor1() throws Exception {
    URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
            Constants.THREAD_NAME_KEY + "=demo&" +
            Constants.CORE_THREADS_KEY + "=1&" +
            Constants.THREADS_KEY + "=2&" +
            Constants.ALIVE_KEY + "=1000&" +
            Constants.QUEUES_KEY + "=0");
    ThreadPool threadPool = new EagerThreadPool();
    ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool.getExecutor(url);
    assertThat(executor, instanceOf(EagerThreadPoolExecutor.class));
    assertThat(executor.getCorePoolSize(), is(1));
    assertThat(executor.getMaximumPoolSize(), is(2));
    assertThat(executor.getKeepAliveTime(TimeUnit.MILLISECONDS), is(1000L));
    assertThat(executor.getQueue().remainingCapacity(), is(1));
    assertThat(executor.getQueue(), Matchers.<BlockingQueue<Runnable>>instanceOf(TaskQueue.class));
    assertThat(executor.getRejectedExecutionHandler(),
            Matchers.<RejectedExecutionHandler>instanceOf(AbortPolicyWithReport.class));

    final CountDownLatch latch = new CountDownLatch(1);
    executor.execute(new Runnable() {
        @Override
        public void run() {
            Thread thread = Thread.currentThread();
            assertThat(thread, instanceOf(InternalThread.class));
            assertThat(thread.getName(), startsWith("demo"));
            latch.countDown();
        }
    });

    latch.await();
    assertThat(latch.getCount(), is(0L));
}
 
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	ScheduledExecutorService executor =
			createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);

	if (this.removeOnCancelPolicy) {
		if (executor instanceof ScheduledThreadPoolExecutor) {
			((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
		}
		else {
			logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
		}
	}

	// Register specified ScheduledExecutorTasks, if necessary.
	if (!ObjectUtils.isEmpty(this.scheduledExecutorTasks)) {
		registerTasks(this.scheduledExecutorTasks, executor);
	}

	// Wrap executor with an unconfigurable decorator.
	this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
			Executors.unconfigurableScheduledExecutorService(executor) : executor);

	return executor;
}
 
源代码14 项目: che   文件: CountedRejectedExecutionHandler.java
public CountedRejectedExecutionHandler(
    RejectedExecutionHandler delegate, MeterRegistry registry, String name, Iterable<Tag> tags) {
  this.delegate = delegate;
  this.counter =
      Counter.builder("executor.rejected")
          .tags(Tags.concat(tags, "name", name))
          .description("The number of tasks not accepted for execution")
          .baseUnit(BaseUnits.TASKS)
          .register(registry);
}
 
源代码15 项目: sofa-rpc   文件: ThreadPoolUtils.java
/**
 * 固定大小线程池,自定义队列、线程池工厂和拒绝策略
 *
 * @param corePoolSize  初始化线程池
 * @param queue         线程池队列
 * @param threadFactory 线程池工厂
 * @param handler       拒绝策略
 * @return the thread pool executor
 */
public static ThreadPoolExecutor newFixedThreadPool(int corePoolSize,
                                                    BlockingQueue<Runnable> queue,
                                                    ThreadFactory threadFactory,
                                                    RejectedExecutionHandler handler) {
    return new ThreadPoolExecutor(corePoolSize,
        corePoolSize,
        0,
        TimeUnit.MILLISECONDS,
        queue,
        threadFactory,
        handler);
}
 
源代码16 项目: openjdk-jdk9   文件: ThreadPoolExecutorTest.java
/**
 * setRejectedExecutionHandler sets the handler returned by
 * getRejectedExecutionHandler
 */
public void testSetRejectedExecutionHandler() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        RejectedExecutionHandler handler = new NoOpREHandler();
        p.setRejectedExecutionHandler(handler);
        assertSame(handler, p.getRejectedExecutionHandler());
    }
}
 
源代码17 项目: sofa-jraft   文件: StoreEngineHelper.java
private static ExecutorService newPool(final int coreThreads, final int maxThreads,
                                       final BlockingQueue<Runnable> workQueue, final String name,
                                       final RejectedExecutionHandler handler) {
    return ThreadPoolUtil.newBuilder() //
        .poolName(name) //
        .enableMetric(true) //
        .coreThreads(coreThreads) //
        .maximumThreads(maxThreads) //
        .keepAliveSeconds(60L) //
        .workQueue(workQueue) //
        .threadFactory(new NamedThreadFactory(name, true)) //
        .rejectedHandler(handler) //
        .build();
}
 
public ThreadPoolTaskExecutor(int corePoolSize, int maximumPoolSize, 
                              long keepAliveTime, TimeUnit unit,
                              BlockingQueue<Runnable> workQueue, 
                              ThreadFactory threadFactory, 
                              RejectedExecutionHandler handler) {
    
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
}
 
public ProcessingLibraryThreadPoolExecutor(int corePoolSize,
        int maximumPoolSize, long keepAliveTime, TimeUnit unit,
        BlockingQueue<Runnable> workQueue,
        RejectedExecutionHandler handler, ExceptionHandler exceptionHandler) {
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
    this.exceptionHandler = exceptionHandler;
}
 
public ClingExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedHandler) {
    // This is the same as Executors.newCachedThreadPool
    super(0,
          Integer.MAX_VALUE,
          60L,
          TimeUnit.SECONDS,
          new SynchronousQueue<Runnable>(),
          threadFactory,
          rejectedHandler
    );
}
 
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = new ThreadPoolExecutor(
			this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
			queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

	this.threadPoolExecutor = executor;
	return executor;
}
 
源代码22 项目: Sentinel-Dashboard-Nacos   文件: MetricFetcher.java
public MetricFetcher() {
    int cores = Runtime.getRuntime().availableProcessors() * 2;
    long keepAliveTime = 0;
    int queueSize = 2048;
    RejectedExecutionHandler handler = new DiscardPolicy();
    fetchService = new ThreadPoolExecutor(cores, cores,
        keepAliveTime, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize),
        new NamedThreadFactory("sentinel-dashboard-metrics-fetchService"), handler);
    fetchWorker = new ThreadPoolExecutor(cores, cores,
        keepAliveTime, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize),
        new NamedThreadFactory("sentinel-dashboard-metrics-fetchWorker"), handler);
    IOReactorConfig ioConfig = IOReactorConfig.custom()
        .setConnectTimeout(3000)
        .setSoTimeout(3000)
        .setIoThreadCount(Runtime.getRuntime().availableProcessors() * 2)
        .build();

    httpclient = HttpAsyncClients.custom()
        .setRedirectStrategy(new DefaultRedirectStrategy() {
            @Override
            protected boolean isRedirectable(final String method) {
                return false;
            }
        }).setMaxConnTotal(4000)
        .setMaxConnPerRoute(1000)
        .setDefaultIOReactorConfig(ioConfig)
        .build();
    httpclient.start();
    start();
}
 
源代码23 项目: sofa-registry   文件: SessionThreadPoolExecutor.java
public SessionThreadPoolExecutor(String executorName, int corePoolSize, int maximumPoolSize,
                                 long keepAliveTime, TimeUnit unit,
                                 BlockingQueue<Runnable> workQueue,
                                 ThreadFactory threadFactory, RejectedExecutionHandler handler) {
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory);
    this.executorName = executorName;
    registerTaskMetrics();
    this.setRejectedExecutionHandler(handler);
}
 
/**
 * Constructor throws if handler is null
 */
public void testConstructorNullPointerException7() {
    try {
        new CustomTPE(1, 2, 1L, SECONDS,
                      new ArrayBlockingQueue<Runnable>(10),
                      new SimpleThreadFactory(),
                      (RejectedExecutionHandler) null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
源代码25 项目: pnc   文件: MDCThreadPoolExecutor.java
public MDCThreadPoolExecutor(
        int corePoolSize,
        int maximumPoolSize,
        long keepAliveTime,
        TimeUnit unit,
        BlockingQueue<Runnable> workQueue,
        RejectedExecutionHandler handler) {
    this.executorService = new ThreadPoolExecutor(
            corePoolSize,
            maximumPoolSize,
            keepAliveTime,
            unit,
            workQueue,
            handler);
}
 
LazyTraceScheduledThreadPoolExecutor(
         int corePoolSize,
ThreadFactory threadFactory,
         RejectedExecutionHandler handler,
         ScheduledThreadPoolExecutor delegate) {
     super(corePoolSize, threadFactory, handler);
     this.delegate = delegate;
     this.decorateTaskRunnable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
             RunnableScheduledFuture.class);
     makeAccessibleIfNotNull(this.decorateTaskRunnable);
     this.decorateTaskCallable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
             RunnableScheduledFuture.class);
     makeAccessibleIfNotNull(this.decorateTaskCallable);
     this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "finalize", null);
     makeAccessibleIfNotNull(this.finalize);
     this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "beforeExecute", null);
     makeAccessibleIfNotNull(this.beforeExecute);
     this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
             "afterExecute", null);
     makeAccessibleIfNotNull(this.afterExecute);
     this.terminated = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class,
             "terminated");
     makeAccessibleIfNotNull(this.terminated);
     this.newTaskForRunnable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
             Object.class);
     makeAccessibleIfNotNull(this.newTaskForRunnable);
     this.newTaskForCallable = ReflectionUtils.findMethod(
             ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
             Object.class);
     makeAccessibleIfNotNull(this.newTaskForCallable);
 }
 
源代码27 项目: Mycat-Balance   文件: SynThreadPoolExecutor.java
public SynThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
        BlockingQueue<Runnable> runnableQueue, ThreadFactory threadFactory, String name)
{
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, (BlockingQueue<Runnable>) runnableQueue, threadFactory);

    RejectedExecutionHandler handler = new DefaultRejectedExecutionHandler(this);
    this.setRejectedExecutionHandler(handler);
    this.name = name;
}
 
LazyTraceScheduledThreadPoolExecutor(
        int corePoolSize,
        RejectedExecutionHandler handler,
        ScheduledThreadPoolExecutor delegate) {
    super(corePoolSize, handler);
    this.delegate = delegate;
    this.decorateTaskRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTask", Runnable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskRunnable);
    this.decorateTaskCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "decorateTaskCallable", Callable.class,
            RunnableScheduledFuture.class);
    makeAccessibleIfNotNull(this.decorateTaskCallable);
    this.finalize = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "finalize", null);
    makeAccessibleIfNotNull(this.finalize);
    this.beforeExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "beforeExecute", null);
    makeAccessibleIfNotNull(this.beforeExecute);
    this.afterExecute = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "afterExecute", null);
    makeAccessibleIfNotNull(this.afterExecute);
    this.terminated = ReflectionUtils.findMethod(ScheduledThreadPoolExecutor.class,
            "terminated", null);
    makeAccessibleIfNotNull(this.terminated);
    this.newTaskForRunnable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Runnable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForRunnable);
    this.newTaskForCallable = ReflectionUtils.findMethod(
            ScheduledThreadPoolExecutor.class, "newTaskFor", Callable.class,
            Object.class);
    makeAccessibleIfNotNull(this.newTaskForCallable);
}
 
源代码29 项目: azeroth   文件: StandardThreadExecutor.java
public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime,
                              TimeUnit unit, int queueCapacity, ThreadFactory threadFactory,
                              RejectedExecutionHandler handler) {
    super(coreThreads, maxThreads, keepAliveTime, unit, new ExecutorQueue(), threadFactory,
        handler);
    ((ExecutorQueue) getQueue()).setStandardThreadExecutor(this);

    submittedTasksCount = new AtomicInteger(0);

    // 最大并发任务限制: 队列buffer数 + 最大线程数 
    maxSubmittedTaskCount = queueCapacity + maxThreads;
}
 
源代码30 项目: pinpoint   文件: ExecutorFactoryBean.java
private ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
    if (registry != null) {
        return newMonitoredExecutorService(corePoolSize, maxPoolSize, keepAliveSeconds, queue, threadFactory, rejectedExecutionHandler);
    }

    return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.MILLISECONDS, queue, threadFactory, rejectedExecutionHandler);
}
 
 类所在包
 类方法
 同包方法