本文整理汇总了Java中org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolTaskScheduler.initialize方法的具体用法?Java ThreadPoolTaskScheduler.initialize怎么用?Java ThreadPoolTaskScheduler.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
的用法示例。
在下文中一共展示了ThreadPoolTaskScheduler.initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Test
public void test() throws InterruptedException {
ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
executor.initialize();
NativeSessionCloser closer = mock(NativeSessionCloser.class);
PingWatchdogManager manager = new PingWatchdogManager(executor, closer);
manager.setPingWatchdog(true);
for (int i = 0; i < 10; i++) {
manager.pingReceived("TransportID", 100);
Thread.sleep(100);
}
Thread.sleep(500);
verify(closer).closeSession("TransportID");
}
示例2: 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);
}
}
示例3: configureTasks
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(50);
taskScheduler.initialize();
taskRegistrar.setTaskScheduler(taskScheduler);
}
示例4: configureTasks
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
threadPoolTaskScheduler.setThreadNamePrefix("SchedulerThreads-");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
}
示例5: taskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Test
public void taskScheduler() {
ThreadPoolTaskScheduler sched = new ThreadPoolTaskScheduler();
sched.initialize();
ExecutorServiceMetrics.monitor(registry, sched.getScheduledExecutor(), "sched");
assertThreadPoolExecutorMetrics("sched");
}
示例6: schedulerTaskExecutor
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
/**
* Thread pool for spring scheduling
*/
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler schedulerTaskExecutor() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(DEFAULT_SCHEDULER_POOL_SIZE);
scheduler.setDaemon(true);
scheduler.setThreadNamePrefix("api-task-");
scheduler.initialize();
return scheduler;
}
示例7: configureTasks
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setThreadNamePrefix("task-pool");
taskScheduler.setPoolSize(10);
taskScheduler.initialize();
taskRegistrar.setTaskScheduler(taskScheduler);
}
示例8: configureTasks
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(5);
taskScheduler.initialize();
taskScheduler.setThreadNamePrefix("ScheduledExecutor-");
taskRegistrar.setTaskScheduler(taskScheduler);
}
示例9: getAsyncExecutor
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(10);
scheduler.initialize();
return scheduler;
}
示例10: makeScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
private TaskScheduler makeScheduler(int poolSize) {
ThreadPoolTaskScheduler tpts = new ThreadPoolTaskScheduler();
tpts.setThreadFactory(makeThreadFactory("scheduler"));
if(poolSize < 1) {
poolSize = 10;
}
tpts.setPoolSize(poolSize);
tpts.initialize();
return tpts;
}
示例11: createTaskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
protected TaskScheduler createTaskScheduler(ShutdownManager shutdownManager) {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(threadPoolSize);
taskScheduler.setThreadNamePrefix("bootique-job-");
taskScheduler.initialize();
shutdownManager.addShutdownHook(taskScheduler::shutdown);
return taskScheduler;
}
示例12: testLateBindingConsumer
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void testLateBindingConsumer() throws Exception {
BindingServiceProperties properties = new BindingServiceProperties();
properties.setBindingRetryInterval(1);
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
props.setDestination("foo");
final String inputChannelName = "input";
bindingProperties.put(inputChannelName, props);
properties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
BindingService service = new BindingService(properties, binderFactory, scheduler);
MessageChannel inputChannel = new DirectChannel();
final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
final CountDownLatch fail = new CountDownLatch(2);
doAnswer(i -> {
fail.countDown();
if (fail.getCount() == 1) {
throw new RuntimeException("fail");
}
return mockBinding;
}).when(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel), any(ConsumerProperties.class));
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel, inputChannelName);
assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(bindings).hasSize(1);
Binding<MessageChannel> binding = TestUtils.getPropertyValue(bindings.iterator().next(), "delegate",
Binding.class);
assertThat(binding).isSameAs(mockBinding);
service.unbindConsumers(inputChannelName);
verify(binder, times(2)).bindConsumer(eq("foo"), isNull(), same(inputChannel),
any(ConsumerProperties.class));
verify(binding).unbind();
binderFactory.destroy();
}
示例13: testLateBindingProducer
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void testLateBindingProducer() throws Exception {
BindingServiceProperties properties = new BindingServiceProperties();
properties.setBindingRetryInterval(1);
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
props.setDestination("foo");
final String outputChannelName = "output";
bindingProperties.put(outputChannelName, props);
properties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
BindingService service = new BindingService(properties, binderFactory, scheduler);
MessageChannel outputChannel = new DirectChannel();
final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
final CountDownLatch fail = new CountDownLatch(2);
doAnswer(i -> {
fail.countDown();
if (fail.getCount() == 1) {
throw new RuntimeException("fail");
}
return mockBinding;
}).when(binder).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class));
Binding<MessageChannel> binding = service.bindProducer(outputChannel, outputChannelName);
assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(binding).isNotNull();
Binding delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class);
assertThat(delegate).isSameAs(mockBinding);
service.unbindProducers(outputChannelName);
verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class));
verify(delegate).unbind();
binderFactory.destroy();
scheduler.destroy();
}
示例14: taskScheduler
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@Bean(destroyMethod = "shutdown")
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setErrorHandler(new ErrorHandler() {
@Override
public void handleError(Throwable t) {
LogManager.getLogger().error("error while handling job", t);
}
});
scheduler.initialize();
return scheduler;
}
示例15: start
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; //导入方法依赖的package包/类
@PostConstruct
public void start() {
Validate.notBlank(cronExpression);
threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setThreadNamePrefix("SpringCronJob");
threadPoolTaskScheduler.initialize();
threadPoolTaskScheduler.schedule(this, new CronTrigger(cronExpression));
}