Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutorConfig.java    From youkefu with Apache License 2.0 6 votes vote down vote up
/**
 * 作业平台使用的线程池
 * @return
 */
@Bean(name = "uKeFuTaskExecutor")
public ThreadPoolTaskExecutor taskExecutor() {

	ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
	// 线程池维护线程的最少数量
	poolTaskExecutor.setCorePoolSize(CORE_POOL_SIZE);
	// 线程池维护线程的最大数量
	poolTaskExecutor.setMaxPoolSize(MAX_POOL_SIZE);
	// 线程池所使用的缓冲队列
	poolTaskExecutor.setQueueCapacity(200);
	// 线程池维护线程所允许的空闲时间
	poolTaskExecutor.setKeepAliveSeconds(30);
	poolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
	poolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
	return poolTaskExecutor;
}
 
Example 2
Source File: AsyncConfiguration.java    From seed with Apache License 2.0 6 votes vote down vote up
@Bean
public Executor mppExecutor(){
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("MppExecutor-");
    executor.setCorePoolSize(this.corePoolSize);
    executor.setMaxPoolSize(this.maxPoolSize);
    executor.setQueueCapacity(this.queueCapacity);
    //队列满的时候,使用的拒绝策略
    //ABORT(缺省)  :不执行,并抛TaskRejectedException异常
    //DISCARD       :不执行,也不抛异常
    //DISCARD_OLDEST:丢弃queue中最旧的那个任务
    //CALLER_RUNS   :不在新线程中执行任务,而是由调用者所在的线程来执行
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();
    return executor;
}
 
Example 3
Source File: PlowThreadPools.java    From plow with Apache License 2.0 5 votes vote down vote up
/**
 * Handles communication with RNDaemon.
 */
@Bean(name="rndCommandExecutor")
public ThreadPoolTaskExecutor rndCommandExecutor() {
    ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
    t.setCorePoolSize(plowCfg.get("plow.rndpool.cache.threads", 8));
    t.setMaxPoolSize(plowCfg.get("plow.rndpool.cache.threads", 8));
    t.setThreadNamePrefix("RndRun");
    t.setDaemon(false);
    t.setQueueCapacity(1000);
    t.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return t;
}
 
Example 4
Source File: MainBeanConfig.java    From Cleanstone with MIT License 5 votes vote down vote up
@Bean
public TaskExecutor worldExec() {
    ThreadPoolTaskExecutor executor = createTaskExecutor(5000, "worldExec");
    executor.setCorePoolSize(10);
    executor.setMaxPoolSize(128);
    executor.setQueueCapacity(50);
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();

    return executor;
}
 
Example 5
Source File: AsyncConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("carapp-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 6
Source File: ThreadConfig.java    From WeBASE-Transaction with Apache License 2.0 5 votes vote down vote up
/**
 * set ThreadPoolTaskExecutor.
 * 
 * @return
 */
@Bean
public ThreadPoolTaskExecutor transExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(50);
    executor.setMaxPoolSize(100);
    executor.setQueueCapacity(500);
    executor.setKeepAliveSeconds(60);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("transExecutor-");
    executor.initialize();
    return executor;
}
 
Example 7
Source File: ThreadPoolConfig.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
@Bean(name = "threadPoolTaskExecutor")
public ThreadPoolTaskExecutor threadPoolTaskExecutor()
{
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(maxPoolSize);
    executor.setCorePoolSize(corePoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAliveSeconds);
    // 线程池对拒绝任务(无线程可用)的处理策略
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return executor;
}
 
Example 8
Source File: Web3Config.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * set sdk threadPool.
 *
 * @return
 */
@Bean
public ThreadPoolTaskExecutor sdkThreadPool() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAlive);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("sdkThreadPool-");
    executor.initialize();
    return executor;
}
 
Example 9
Source File: Application.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(10);
    executor.setCorePoolSize(5);
    executor.initialize();
    return executor;
}
 
Example 10
Source File: ThreadHelper.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
public static ThreadPoolTaskExecutor createTaskExecutor(int maxPoolSize,
                                                        int corePoolSize,
                                                        int queueSize,
                                                        String threadNamePrefix) {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(corePoolSize);
    taskExecutor.setMaxPoolSize(maxPoolSize);
    taskExecutor.setQueueCapacity(queueSize);
    taskExecutor.setThreadNamePrefix(threadNamePrefix);
    taskExecutor.setDaemon(true);

    taskExecutor.initialize();
    return taskExecutor;
}
 
Example 11
Source File: ProvisioningContext.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * Used by {@link org.apache.syncope.core.provisioning.java.propagation.PriorityPropagationTaskExecutor}.
 *
 * @return executor
 */
@Bean
public Executor propagationTaskExecutorAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(env.getProperty("propagationTaskExecutorAsyncExecutor.corePoolSize", Integer.class));
    executor.setMaxPoolSize(env.getProperty("propagationTaskExecutorAsyncExecutor.maxPoolSize", Integer.class));
    executor.setQueueCapacity(env.getProperty("propagationTaskExecutorAsyncExecutor.queueCapacity", Integer.class));
    executor.setThreadNamePrefix("PropagationTaskExecutor-");
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    executor.initialize();
    return executor;
}
 
Example 12
Source File: AsyncConfiguration.java    From spring-boot-completable-future with MIT License 5 votes vote down vote up
@Bean (name = "taskExecutor")
public Executor taskExecutor() {
    LOGGER.debug("Creating Async Task Executor");
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(2);
    executor.setMaxPoolSize(2);
    executor.setQueueCapacity(25);
    executor.setThreadNamePrefix("CarThread-");
    executor.initialize();
    return executor;
}
 
Example 13
Source File: RuleTagPostLoaderProcessor.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initializeThreadPool() {
  executor = new ThreadPoolTaskExecutor();
  executor.setCorePoolSize(threadPoolMin);
  executor.setMaxPoolSize(threadPoolMax);
  executor.setKeepAliveSeconds(THREAD_IDLE_LIMIT);
  executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
  executor.initialize();
}
 
Example 14
Source File: AsyncConfig.java    From springboot-guide with Apache License 2.0 5 votes vote down vote up
@Bean
public Executor taskExecutor() {
  ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  // 核心线程数
  executor.setCorePoolSize(CORE_POOL_SIZE);
  // 最大线程数
  executor.setMaxPoolSize(MAX_POOL_SIZE);
  // 队列大小
  executor.setQueueCapacity(QUEUE_CAPACITY);
  // 当最大池已满时,此策略保证不会丢失任务请求,但是可能会影响应用程序整体性能。
  executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  executor.setThreadNamePrefix("My ThreadPoolTaskExecutor-");
  executor.initialize();
  return executor;
}
 
Example 15
Source File: AsyncConfiguration.java    From jhipster-registry with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(taskExecutionProperties.getPool().getCoreSize());
    executor.setMaxPoolSize(taskExecutionProperties.getPool().getMaxSize());
    executor.setQueueCapacity(taskExecutionProperties.getPool().getQueueCapacity());
    executor.setThreadNamePrefix(taskExecutionProperties.getThreadNamePrefix());
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
 
Example 16
Source File: ThreadPoolConfig.java    From supplierShop with MIT License 5 votes vote down vote up
@Bean(name = "threadPoolTaskExecutor")
public ThreadPoolTaskExecutor threadPoolTaskExecutor()
{
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(maxPoolSize);
    executor.setCorePoolSize(corePoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAliveSeconds);
    // 线程池对拒绝任务(无线程可用)的处理策略
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    return executor;
}
 
Example 17
Source File: CloudVisionAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "cloudVisionExecutor")
public Executor cloudVisionExecutor() {
	ThreadPoolTaskExecutor ackExecutor = new ThreadPoolTaskExecutor();
	ackExecutor.setMaxPoolSize(this.cloudVisionProperties.getExecutorThreadsCount());
	ackExecutor.setThreadNamePrefix("gcp-cloud-vision-ocr-executor");
	ackExecutor.setDaemon(true);
	return ackExecutor;
}
 
Example 18
Source File: TaskConfiguration.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Bean("taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(100);
        executor.setMaxPoolSize(400);
        executor.setQueueCapacity(400);
        executor.setKeepAliveSeconds(60);
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.setAwaitTerminationSeconds(60);
        executor.setThreadNamePrefix("taskExecutor-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
//        executor.setTaskDecorator(new GrayTaskDecorator());
        return executor;
    }
 
Example 19
Source File: TaskExecutorFactoryBean.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void determinePoolSizeRange(ThreadPoolTaskExecutor executor) {
	if (StringUtils.hasText(this.poolSize)) {
		try {
			int corePoolSize;
			int maxPoolSize;
			int separatorIndex = this.poolSize.indexOf('-');
			if (separatorIndex != -1) {
				corePoolSize = Integer.valueOf(this.poolSize.substring(0, separatorIndex));
				maxPoolSize = Integer.valueOf(this.poolSize.substring(separatorIndex + 1, this.poolSize.length()));
				if (corePoolSize > maxPoolSize) {
					throw new IllegalArgumentException(
							"Lower bound of pool-size range must not exceed the upper bound");
				}
				if (this.queueCapacity == null) {
					// No queue-capacity provided, so unbounded
					if (corePoolSize == 0) {
						// Actually set 'corePoolSize' to the upper bound of the range
						// but allow core threads to timeout...
						executor.setAllowCoreThreadTimeOut(true);
						corePoolSize = maxPoolSize;
					}
					else {
						// Non-zero lower bound implies a core-max size range...
						throw new IllegalArgumentException(
								"A non-zero lower bound for the size range requires a queue-capacity value");
					}
				}
			}
			else {
				Integer value = Integer.valueOf(this.poolSize);
				corePoolSize = value;
				maxPoolSize = value;
			}
			executor.setCorePoolSize(corePoolSize);
			executor.setMaxPoolSize(maxPoolSize);
		}
		catch (NumberFormatException ex) {
			throw new IllegalArgumentException("Invalid pool-size value [" + this.poolSize + "]: only single " +
					"maximum integer (e.g. \"5\") and minimum-maximum range (e.g. \"3-5\") are supported", ex);
		}
	}
}
 
Example 20
Source File: PerformanceDTTest.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Stress tests that create tx and sign them
 *
 * @param totalSignedTxCount
 * @param threadC
 * @throws InterruptedException
 */
public void userTransferSignTxPerfTest(BigInteger totalSignedTxCount, int threadC)
        throws InterruptedException {

    ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();

    threadPool.setCorePoolSize(threadC > 0 ? threadC : 10);
    threadPool.setMaxPoolSize(threadC > 0 ? threadC : 10);
    threadPool.setQueueCapacity(threadC > 0 ? threadC : 10);
    threadPool.initialize();

    Credentials credentials = GenCredential.create();

    TransferSignTransactionManager extendedRawTransactionManager =
            new TransferSignTransactionManager(
                    null, credentials, BigInteger.ONE, BigInteger.ONE);

    dagTransfer =
            DagTransfer.load(
                    dagTransferAddr,
                    null,
                    extendedRawTransactionManager,
                    new StaticGasProvider(
                            new BigInteger("30000000"), new BigInteger("30000000")));

    AtomicLong signed = new AtomicLong(0);

    long startTime = System.currentTimeMillis();
    System.out.println(" => " + dateFormat.format(new Date()));

    for (int i = 0; i < threadC; i++) {
        threadPool.execute(
                new Runnable() {
                    @Override
                    public void run() {
                        while (true) {

                            long index = signed.incrementAndGet();
                            if (index > totalSignedTxCount.intValue()) {
                                break;
                            }
                            DagTransferUser from = dagUserMgr.getFrom((int) index);
                            DagTransferUser to = dagUserMgr.getTo((int) index);

                            Random random = new Random();
                            int r = random.nextInt(100) + 1;
                            BigInteger amount = BigInteger.valueOf(r);

                            try {
                                String signedTransaction =
                                        dagTransfer.userTransferSeq(
                                                from.getUser(), to.getUser(), amount);

                                if (index % (totalSignedTxCount.longValue() / 10) == 0) {
                                    System.out.println(
                                            "Signed transaction: "
                                                    + String.valueOf(
                                                            index
                                                                    * 100
                                                                    / totalSignedTxCount
                                                                            .longValue())
                                                    + "%");
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                System.exit(-1);
                            }
                        }
                    }
                });
    }

    while (signed.get() < totalSignedTxCount.intValue()) {
        Thread.sleep(10);
    }

    long endTime = System.currentTimeMillis();
    double elapsed = (endTime - startTime) / 1000.0;

    System.out.println(" => " + dateFormat.format(new Date()));

    System.out.print(
            " sign transactions finished, elapse time: "
                    + elapsed
                    + ", tx count = "
                    + totalSignedTxCount
                    + " ,sps = "
                    + (totalSignedTxCount.intValue() / elapsed));
    System.exit(0);
}