本文整理汇总了Java中org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler类的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolTaskScheduler类的具体用法?Java ThreadPoolTaskScheduler怎么用?Java ThreadPoolTaskScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadPoolTaskScheduler类属于org.springframework.scheduling.concurrent包,在下文中一共展示了ThreadPoolTaskScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: taskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
public ThreadPoolTaskScheduler taskScheduler()
{
logger.info("Setting up thread pool task scheduler with 20 threads.");
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(20);
scheduler.setThreadNamePrefix("task-");
scheduler.setAwaitTerminationSeconds(60);
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setErrorHandler(t -> schedulingLogger.error(
"Unknown error occurred while executing task.", t
));
scheduler.setRejectedExecutionHandler(
(r, e) -> schedulingLogger.error(
"Execution of task {} was rejected for unknown reasons.", r
)
);
return scheduler;
}
示例2: messageListenerContainer
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
public MessageListenerContainer messageListenerContainer(
ConsumerFactory<String, DefaultAvMessage> consumerFactory,
MessageListener<String, AvMessage> messageListener,
ThreadPoolTaskScheduler kafkaClientThreadPoolTaskScheduler
) {
ContainerProperties props = new ContainerProperties(resultTopic);
// shouldn't be necessary but the default scheduler is not destroyed after shutdown
props.setScheduler(kafkaClientThreadPoolTaskScheduler);
MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
consumerFactory,
props
);
container.setupMessageListener(messageListener);
return container;
}
示例3: postProcessAfterInitialization
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Test
public void postProcessAfterInitialization() throws Exception {
assertThat(processor.postProcessAfterInitialization(mock(Executor.class), toBeExcluded).getClass(),
not(equalTo(ContextAwareExecutor.class)));
//concurrent
assertThat(processor.postProcessAfterInitialization(mock(Executor.class), beanName).getClass(),
equalTo(ContextAwareExecutor.class));
assertThat(processor.postProcessAfterInitialization(mock(ExecutorService.class), beanName).getClass(),
equalTo(ContextAwareExecutorService.class));
assertThat(processor.postProcessAfterInitialization(mock(ScheduledExecutorService.class), beanName).getClass(),
equalTo(ContextAwareScheduledExecutorService.class));
//spring
assertThat(processor.postProcessAfterInitialization(mock(TaskScheduler.class), beanName).getClass(),
equalTo(ContextAwareTaskScheduler.class));
assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskExecutor(), beanName).getClass(),
equalTo(ContextAwareThreadPoolTaskExecutor.class));
assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskScheduler(), beanName).getClass(),
equalTo(ContextAwareThreadPoolTaskScheduler.class));
assertThat(processor.postProcessAfterInitialization(mock(AsyncListenableTaskExecutor.class), beanName).getClass(),
equalTo(ContextAwareAsyncListenableTaskExecutor.class));
assertThat(processor.postProcessAfterInitialization(mock(AsyncTaskExecutor.class), beanName).getClass(),
equalTo(ContextAwareAsyncTaskExecutor.class));
assertThat(processor.postProcessAfterInitialization(mock(SchedulingTaskExecutor.class), beanName).getClass(),
equalTo(ContextAwareSchedulingTaskExecutor.class));
}
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:27,代码来源:PreservesExecutionContextExecutorStrategyTest.java
示例4: bbTaskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
public TaskScheduler bbTaskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setThreadNamePrefix("API-Schd-ThrP-");
taskScheduler.setAwaitTerminationSeconds(1);
taskScheduler.setRejectedExecutionHandler(new ThreadPoolTaskRejectedHandler());
return taskScheduler;
}
示例5: afterPropertiesSet
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
public void afterPropertiesSet() {
if (properties != null) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if ("scheduler.enabled".equals(key)) {
continue;
}
if (key.startsWith(prefix)) {
String name = key.substring(prefix.length());
skipMap.put(name, Boolean.valueOf(value));
logger.info("{} : {}", name, skipMap.get(name));
}
}
}
if (enabled) {
instance = new ThreadPoolTaskScheduler();
instance.afterPropertiesSet();
}
}
示例6: stompClient
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(MessageConverter messageConverter,
ThreadPoolTaskScheduler taskScheduler) {
int bufferSizeLimit = 1024 * 1024 * 8;
StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
List<Transport> transports = new ArrayList<>();
transports.add(new WebSocketTransport(webSocketClient));
SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient client = new WebSocketStompClient(sockJsClient);
client.setInboundMessageSizeLimit(bufferSizeLimit);
client.setMessageConverter(messageConverter);
client.setTaskScheduler(taskScheduler);
client.setDefaultHeartbeat(new long[]{0, 0});
return client;
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:18,代码来源:ZuulWebSocketConfiguration.java
示例7: RedisTestBinder
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
public RedisTestBinder(RedisConnectionFactory connectionFactory) {
RedisMessageChannelBinder binder = new RedisMessageChannelBinder(connectionFactory);
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
new DefaultMessageBuilderFactory());
DefaultHeaderChannelRegistry channelRegistry = new DefaultHeaderChannelRegistry();
channelRegistry.setReaperDelay(Long.MAX_VALUE);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
channelRegistry.setTaskScheduler(taskScheduler);
context.getBeanFactory().registerSingleton(
IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
channelRegistry);
context.refresh();
binder.setApplicationContext(context);
binder.setCodec(new PojoCodec());
setBinder(binder);
template = new StringRedisTemplate(connectionFactory);
}
示例8: taskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
String levelString = context.getInitParameter("threadNumber");
if (levelString == null) {
levelString = "4";
}
int level = Integer.parseInt(levelString);
log.info("Creating thread pool with " + level + " threads");
ThreadPoolTaskScheduler exec = new ThreadPoolTaskScheduler();
exec.setPoolSize(level);
exec.setThreadNamePrefix("transaction");
exec.setAwaitTerminationSeconds(60);
exec.setWaitForTasksToCompleteOnShutdown(true);
exec.setRejectedExecutionHandler(new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
StringBuilder errorBuilder = new StringBuilder("Task Rejected");
log.error(errorBuilder.toString());
}
});
return exec;
}
示例9: vaultTaskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
/**
* Creates a new {@link TaskSchedulerWrapper} that encapsulates a bean implementing
* {@link TaskScheduler} and {@link AsyncTaskExecutor}.
*
* @return
* @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
applicationContext.registerShutdownHook();
return new TaskSchedulerWrapper(threadPoolTaskScheduler);
}
示例10: fileServerMessageListenerContainer
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Bean
public MessageListenerContainer fileServerMessageListenerContainer(
ConsumerFactory<String, DefaultAvMessage> consumerFactory,
MessageListener<String, AvMessage> fileServerMessageListener,
ThreadPoolTaskScheduler kafkaServerThreadPoolTaskScheduler
) {
ContainerProperties props = new ContainerProperties(fileTopic);
// shouldn't be necessary but the default scheduler is not destroyed after shutdown
props.setScheduler(kafkaServerThreadPoolTaskScheduler);
MessageListenerContainer container = new ConcurrentMessageListenerContainer<>(
consumerFactory,
props
);
container.setupMessageListener(fileServerMessageListener);
return container;
}
示例11: init
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.detectionTasks = new HashMap<>();
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例12: init
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.executionEngine.setActionMonitor(actionMonitor);
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例13: init
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@PostConstruct
public void init() {
this.actionMonitor = new ActionMonitor();
this.taskScheduler = new ThreadPoolTaskScheduler();
this.taskScheduler.setPoolSize(10);
this.taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
this.taskScheduler.setRemoveOnCancelPolicy(true);
this.taskScheduler.setErrorHandler(
new ErrorHandler() {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public void handleError(Throwable t) {
log.error(t.getMessage(), t);
}
});
this.taskScheduler.initialize();
}
示例14: afterPropertiesSet
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
final Environment env = beanFactory.getBean(Environment.class);
TaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
final String schedulerBeanName = taskScheduler.getClass().getName();
beanFactory.registerSingleton(schedulerBeanName, taskScheduler);
beanFactory.initializeBean(taskScheduler, schedulerBeanName);
final String inMemoryServerAddress = getRatelServiceAddress(env);
final DiscoveryClient discoveryClient = new DiscoveryClient(inMemoryServerAddress);
this.ratelServerFetcher = new RatelServerFetcher(discoveryClient);
this.ratelServerProxyGenerator = new RatelServerProxyGenerator(beanFactory);
this.ratelServerRegistry = new RatelServerRegistry(new RemoteRestDiscoveryServer(inMemoryServerAddress),
taskScheduler);
}
示例15: initBackgroundJobs
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入依赖的package包/类
protected void initBackgroundJobs(WebApplicationContext ctx) {
try {
IConfigurationService configurationService = ctx.getBean(IConfigurationService.class);
IImportExportService importExportService = ctx.getBean(IImportExportService.class);
IOperationsService operationsService = ctx.getBean(IOperationsService.class);
jobScheduler = new ThreadPoolTaskScheduler();
jobScheduler.setDaemon(true);
jobScheduler.setThreadNamePrefix("background-job-");
jobScheduler.setPoolSize(2);
jobScheduler.initialize();
TypedProperties properties = operationsService.findGlobalSetttingsAsProperties();
if (properties.is(CONFIG_BACKUP_ENABLED, DEFAULT_CONFIG_BACKUP_ENABLED)) {
jobScheduler.schedule(new BackupJob(importExportService, configurationService, operationsService, getConfigDir(false)),
new CronTrigger(
properties.get(CONFIG_BACKUP_CRON, DEFAULT_CONFIG_BACKUP_CRON)));
}
jobScheduler.scheduleAtFixedRate(() -> configurationService.doInBackground(), 600000);
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).info("Failed to schedule the backup job", e);
}
}