Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setThreadNamePrefix()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setThreadNamePrefix() . 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: ConfigWatch.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
private List<ThreadPoolTaskScheduler> getTaskSchedulers() {
    List<ThreadPoolTaskScheduler> taskSchedulers = new ArrayList<>();
    Object[] keys = consulIndexes.keySet().toArray();
    for (int i = 0; i < consulIndexes.size(); i++) {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = getTaskScheduler();
        if (!StringUtils.isEmpty(keys[i])) {
            String[] keyArray = keys[i].toString().split("/");
            if (keyArray.length >= 1) {
                keys[i] = keyArray[keyArray.length - 1];
                threadPoolTaskScheduler.setThreadNamePrefix(keys[i] + "-");
            }
        }
        taskSchedulers.add(threadPoolTaskScheduler);
    }
    return taskSchedulers;
}
 
Example 2
Source File: StackdriverTraceAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(name = "traceExecutorProvider")
public ExecutorProvider traceExecutorProvider(GcpTraceProperties traceProperties, @Qualifier("traceSenderThreadPool") Optional<ThreadPoolTaskScheduler> userProvidedScheduler) {
	ThreadPoolTaskScheduler scheduler;
	if (userProvidedScheduler.isPresent()) {
		scheduler = userProvidedScheduler.get();
	}
	else {
		this.defaultTraceSenderThreadPool = new ThreadPoolTaskScheduler();
		scheduler = this.defaultTraceSenderThreadPool;
		scheduler.setPoolSize(traceProperties.getNumExecutorThreads());
		scheduler.setThreadNamePrefix("gcp-trace-sender");
		scheduler.setDaemon(true);
		scheduler.initialize();
	}
	return FixedExecutorProvider.create(scheduler.getScheduledExecutor());
}
 
Example 3
Source File: SchedulerConfig.java    From code-examples with MIT License 5 votes vote down vote up
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();

    scheduler.setPoolSize(POOL_SIZE);
    scheduler.setThreadNamePrefix("My-Scheduler-");
    scheduler.initialize();

    taskRegistrar.setTaskScheduler(scheduler);
}
 
Example 4
Source File: WebRestApiApplication.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
@Bean(BEANNAME_WebuiTaskScheduler)
public TaskScheduler webuiTaskScheduler()
{
	final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setThreadNamePrefix("webui-task-scheduler-");
	taskScheduler.setDaemon(true);
	taskScheduler.setPoolSize(10);
	return taskScheduler;
}
 
Example 5
Source File: SchedulingConfiguration.java    From dk-foundation with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(systemSchedulePoolsize);
    scheduler.setThreadNamePrefix("dispatch-");
    scheduler.setAwaitTerminationSeconds(600);
    scheduler.setErrorHandler(throwable -> logger.error("调度任务发生异常", throwable));
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    return scheduler;
}
 
Example 6
Source File: SchedulingConfig.java    From NettyReverseProxy with Apache License 2.0 5 votes vote down vote up
@Bean(name = "taskScheduler")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(10);
    scheduler.setDaemon(true);
    scheduler.setThreadNamePrefix("taskScheduler-");
    return scheduler;
}
 
Example 7
Source File: HttpClientConfig.java    From wecube-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("poolScheduler");
    scheduler.setPoolSize(httpClientProperties.getPoolSizeOfScheduler());
    return scheduler;
}
 
Example 8
Source File: TimerTaskConfig.java    From littleca with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    //线程池大小
    scheduler.setPoolSize(1);
    //线程名字前缀
    scheduler.setThreadNamePrefix("cert-timer-task");
    return scheduler;
}
 
Example 9
Source File: DatabaseMySQLTraceLogFlushHandler.java    From summerframework with Apache License 2.0 5 votes vote down vote up
public DatabaseMySQLTraceLogFlushHandler(DataSource dataSource) {
    Assert.notNull(dataSource, "DatabaseTraceLogFlushHandler must have dataSource.");
    this.dataSource = dataSource;
    doWithConnection(createTableIfNotExist);
    tableReady = true;
    threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setDaemon(true);
    threadPoolTaskScheduler.setThreadNamePrefix("TraceLogFlush");
    threadPoolTaskScheduler.initialize();
    threadPoolTaskScheduler.schedule(cleanerTask,
        new CronTrigger(System.getProperty("rabbit.trace.flush.trigger", "0 0 1 * * ?")));
}
 
Example 10
Source File: ScheduleConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new MDCCleanerThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(taskSchedulerPoolSize);
    threadPoolTaskScheduler.setThreadNamePrefix("scheduledExecutor-");
    return threadPoolTaskScheduler;
}
 
Example 11
Source File: EnableSchedulingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler1() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler1");
	return scheduler;
}
 
Example 12
Source File: EnableSchedulingTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler1() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler1");
	return scheduler;
}
 
Example 13
Source File: SyncConfiguration.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("sync-");
    return scheduler;
}
 
Example 14
Source File: SyncConfiguration.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("sync-");
    return scheduler;
}
 
Example 15
Source File: EnableSchedulingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler2() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler2");
	return scheduler;
}
 
Example 16
Source File: SubscriptionsConfiguration.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setThreadNamePrefix("refresher-");
    return scheduler;
}
 
Example 17
Source File: EnableSchedulingTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler1() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler1");
	return scheduler;
}
 
Example 18
Source File: EnableSchedulingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler1() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler1");
	return scheduler;
}
 
Example 19
Source File: EnableSchedulingTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskScheduler taskScheduler1() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("explicitScheduler1");
	return scheduler;
}
 
Example 20
Source File: WebSocketConfigurationSupport.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * The default TaskScheduler to use if none is registered explicitly via
 * {@link SockJsServiceRegistration#setTaskScheduler}:
 * <pre class="code">
 * &#064;Configuration
 * &#064;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;
}