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

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setRemoveOnCancelPolicy() . 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: ThreadUtils.java    From rqueue with Apache License 2.0 5 votes vote down vote up
public static ThreadPoolTaskScheduler createTaskScheduler(
    int poolSize, String threadPrefix, int terminationTime) {
  ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
  scheduler.setBeanName(threadPrefix.substring(0, threadPrefix.length() - 1));
  scheduler.setPoolSize(poolSize);
  scheduler.setThreadNamePrefix(threadPrefix);
  scheduler.setAwaitTerminationSeconds(terminationTime);
  scheduler.setRemoveOnCancelPolicy(true);
  scheduler.afterPropertiesSet();
  return scheduler;
}
 
Example 2
Source File: AbstractMessageBrokerConfiguration.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Bean(name = {"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("MessageBroker-");
	scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
	scheduler.setRemoveOnCancelPolicy(true);
	return scheduler;
}
 
Example 3
Source File: TaskSchedulerConfig.java    From seppb with MIT License 5 votes vote down vote up
@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 4
Source File: AbstractMessageBrokerConfiguration.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean(name = {"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("MessageBroker-");
	scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
	scheduler.setRemoveOnCancelPolicy(true);
	return scheduler;
}
 
Example 5
Source File: WebSocketAutoConfiguration.java    From graphql-spqr-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
private TaskScheduler defaultTaskScheduler() {
    ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
    threadPoolScheduler.setThreadNamePrefix("GraphQLWSKeepAlive-");
    threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
    threadPoolScheduler.setRemoveOnCancelPolicy(true);
    threadPoolScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
    threadPoolScheduler.initialize();
    return threadPoolScheduler;
}
 
Example 6
Source File: SpringScheduledConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Bean()
public ThreadPoolTaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(100);
scheduler.setThreadNamePrefix("Scheduler-");
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setRemoveOnCancelPolicy(true);
   return scheduler;
}
 
Example 7
Source File: AbstractMessageBrokerConfiguration.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean(name={"messageBrokerTaskScheduler", "messageBrokerSockJsTaskScheduler"})
public ThreadPoolTaskScheduler messageBrokerTaskScheduler() {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix("MessageBroker-");
	scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
	scheduler.setRemoveOnCancelPolicy(true);
	return scheduler;
}
 
Example 8
Source File: RegistrationApplicationListener.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
private static ThreadPoolTaskScheduler registrationTaskScheduler() {
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setPoolSize(1);
	taskScheduler.setRemoveOnCancelPolicy(true);
	taskScheduler.setThreadNamePrefix("registrationTask");
	return taskScheduler;
}
 
Example 9
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;
}
 
Example 10
Source File: WebSocketConfigurationSupport.java    From java-technology-stack 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;
}
 
Example 11
Source File: WebSocketConfigurationSupport.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * The default TaskScheduler to use if none is configured via
 * {@link SockJsServiceRegistration#setTaskScheduler}, i.e.
 * <pre class="code">
 * &#064;Configuration
 * &#064;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;
}