Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setPoolSize()
The following examples show how to use
org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setPoolSize() .
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: VaultBootstrapConfiguration.java From spring-cloud-vault with Apache License 2.0 | 6 votes |
/** * Creates a new {@link TaskSchedulerWrapper} that encapsulates a bean implementing * {@link TaskScheduler} and {@link AsyncTaskExecutor}. * @return the {@link TaskSchedulerWrapper} bean. * @see ThreadPoolTaskScheduler */ @Bean @Lazy @ConditionalOnMissingBean(TaskSchedulerWrapper.class) public TaskSchedulerWrapper vaultTaskScheduler() { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setPoolSize(2); threadPoolTaskScheduler.setDaemon(true); threadPoolTaskScheduler.setThreadNamePrefix("Spring-Cloud-Vault-"); // This is to destroy bootstrap resources // otherwise, the bootstrap context is not shut down cleanly this.applicationContext.registerShutdownHook(); return new TaskSchedulerWrapper(threadPoolTaskScheduler); }
Example 2
Source File: SchedulerConfig.java From springboot-guide with Apache License 2.0 | 5 votes |
@Override public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setPoolSize(POOL_SIZE); threadPoolTaskScheduler.setThreadNamePrefix("my-scheduled-task-pool-"); threadPoolTaskScheduler.initialize(); scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler); }
Example 3
Source File: ScheduleConfig.java From Alice-LiveMan with GNU Affero General Public License v3.0 | 5 votes |
@Bean(destroyMethod = "shutdown") public ThreadPoolTaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(10); scheduler.setThreadNamePrefix("task-"); //设置线程名开头 scheduler.setAwaitTerminationSeconds(120); scheduler.setWaitForTasksToCompleteOnShutdown(true); return scheduler; }
Example 4
Source File: ScheduledThreadPoolConfig.java From hdw-dubbo with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "shutdown") public ThreadPoolTaskScheduler taskScheduler() { ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler(); // 设置默认线程名称 executor.setThreadNamePrefix(env.getProperty("spring.application.name") + "-task-"); // 设置最大线程数 executor.setPoolSize(new Double(Math.floor(Runtime.getRuntime().availableProcessors() / (1 - 0.9))).intValue()); // 设置线程活跃时间(秒) executor.setAwaitTerminationSeconds(60); // 设置拒绝策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 等待所有任务结束后再关闭线程池 executor.setWaitForTasksToCompleteOnShutdown(true); return executor; }
Example 5
Source File: Front50WebConfig.java From front50 with Apache License 2.0 | 5 votes |
@Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setThreadNamePrefix("scheduler-"); scheduler.setPoolSize(10); return scheduler; }
Example 6
Source File: TimerTaskConfig.java From littleca with Apache License 2.0 | 5 votes |
@Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); //线程池大小 scheduler.setPoolSize(1); //线程名字前缀 scheduler.setThreadNamePrefix("cert-timer-task"); return scheduler; }
Example 7
Source File: ZuulWebSocketConfiguration.java From spring-cloud-netflix-zuul-websocket with Apache License 2.0 | 5 votes |
@Bean @Qualifier("proxyStompClientTaskScheduler") public TaskScheduler stompClientTaskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setThreadNamePrefix("ProxyStompClient-"); scheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); return scheduler; }
Example 8
Source File: SchedulerConfig.java From bearchoke with Apache License 2.0 | 5 votes |
@Bean(name = "taskScheduler") public ThreadPoolTaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(5); scheduler.setWaitForTasksToCompleteOnShutdown(false); return scheduler; }
Example 9
Source File: ScheduledTaskConfig.java From bugsnag-java with MIT License | 5 votes |
@ConditionalOnProperty(name = "custom_task_scheduler_bean", havingValue = "true") @Bean public TaskScheduler customTaskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(4); return scheduler; }
Example 10
Source File: ApacheHttpClientConfig.java From sfg-blog-posts with GNU General Public License v3.0 | 5 votes |
@Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setThreadNamePrefix("idleMonitor"); scheduler.setPoolSize(5); return scheduler; }
Example 11
Source File: TaskSchedulerConfig.java From seppb with MIT License | 5 votes |
@Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(6); scheduler.setThreadNamePrefix("scheduled-task-"); scheduler.setDaemon(true); return scheduler; }
Example 12
Source File: TaskSchedulerConfig.java From seppb with MIT License | 5 votes |
@Bean public static ThreadPoolTaskScheduler createThreadPoolTaskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(4); taskScheduler.setRemoveOnCancelPolicy(true); taskScheduler.setBeanName("status-update-pool"); taskScheduler.setErrorHandler(e -> log.error("error:", e)); return taskScheduler; }
Example 13
Source File: SchedulingConfigurerConfiguration.java From tutorial with MIT License | 5 votes |
@Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { if (log.isTraceEnabled()) { log.trace("configure scheduling tasks."); } ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setPoolSize(10); // 设置有多少线程负责执行定时任务,默认只有1个。 taskScheduler.initialize(); taskRegistrar.setTaskScheduler(taskScheduler); }
Example 14
Source File: TasksAutoConfiguration.java From genie with Apache License 2.0 | 5 votes |
/** * Get a task scheduler. * * @param tasksSchedulerPoolProperties The properties regarding the thread pool to use for task scheduling * @return The task scheduler */ @Bean @ConditionalOnMissingBean(name = "genieTaskScheduler") public ThreadPoolTaskScheduler genieTaskScheduler( final TasksSchedulerPoolProperties tasksSchedulerPoolProperties ) { final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(tasksSchedulerPoolProperties.getSize()); scheduler.setThreadNamePrefix(tasksSchedulerPoolProperties.getThreadNamePrefix()); return scheduler; }
Example 15
Source File: SpringScheduledConfig.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Bean() public ThreadPoolTaskScheduler taskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(100); scheduler.setThreadNamePrefix("Scheduler-"); scheduler.setWaitForTasksToCompleteOnShutdown(true); scheduler.setRemoveOnCancelPolicy(true); return scheduler; }
Example 16
Source File: DefaultSpringEventRegistryChangeDetectionExecutor.java From flowable-engine with Apache License 2.0 | 4 votes |
protected void createDefaultTaskScheduler() { threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setPoolSize(1); threadPoolTaskScheduler.setThreadNamePrefix("flowable-event-change-detector-"); taskScheduler = threadPoolTaskScheduler; }
Example 17
Source File: ITSchedulerConfiguration.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
@Bean public ThreadPoolTaskScheduler threadPoolTaskScheduler() { final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setPoolSize(1); return scheduler; }
Example 18
Source File: MainBeanConfig.java From Cleanstone with MIT License | 4 votes |
@Bean public ThreadPoolTaskScheduler taskScheduler() { ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler(); threadPoolTaskScheduler.setPoolSize(10); return threadPoolTaskScheduler; }
Example 19
Source File: WebSocketConfigurationSupport.java From java-technology-stack with MIT License | 3 votes |
/** * The default TaskScheduler to use if none is registered explicitly via * {@link SockJsServiceRegistration#setTaskScheduler}: * <pre class="code"> * @Configuration * @EnableWebSocket * public class WebSocketConfig implements WebSocketConfigurer { * * public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { * registry.addHandler(myHandler(), "/echo") * .withSockJS() * .setTaskScheduler(myScheduler()); * } * * // ... * } * </pre> */ @Bean @Nullable public TaskScheduler defaultSockJsTaskScheduler() { if (initHandlerRegistry().requiresTaskScheduler()) { ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler(); threadPoolScheduler.setThreadNamePrefix("SockJS-"); threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); threadPoolScheduler.setRemoveOnCancelPolicy(true); this.scheduler = threadPoolScheduler; } return this.scheduler; }
Example 20
Source File: WebSocketConfigurationSupport.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * The default TaskScheduler to use if none is configured via * {@link SockJsServiceRegistration#setTaskScheduler}, i.e. * <pre class="code"> * @Configuration * @EnableWebSocket * public class WebSocketConfig implements WebSocketConfigurer { * * public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { * registry.addHandler(myWsHandler(), "/echo").withSockJS().setTaskScheduler(myScheduler()); * } * * // ... * } * </pre> */ @Bean public ThreadPoolTaskScheduler defaultSockJsTaskScheduler() { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.setThreadNamePrefix("SockJS-"); scheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); scheduler.setRemoveOnCancelPolicy(true); return scheduler; }