本文整理汇总了Java中org.springframework.scheduling.concurrent.ConcurrentTaskScheduler类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentTaskScheduler类的具体用法?Java ConcurrentTaskScheduler怎么用?Java ConcurrentTaskScheduler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentTaskScheduler类属于org.springframework.scheduling.concurrent包,在下文中一共展示了ConcurrentTaskScheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
public static void main(String... argv) {
WebSocketClient webSocketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
String url = "ws://127.0.0.1:8080/hello";
StompSessionHandler sessionHandler = new MySessionHandler();
stompClient.connect(url, sessionHandler);
new Scanner(System.in).nextLine(); //Don't close immediately.
}
示例2: configureTasks
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
if (properties.isEnabled()) {
TaskScheduler taskScheduler = null;
try {
taskScheduler = this.beanFactory.getBean(TaskScheduler.class);
} catch (NoUniqueBeanDefinitionException e) {
taskScheduler = this.beanFactory.getBean("taskScheduler", TaskScheduler.class);
} catch (NoSuchBeanDefinitionException ex) {
log.warn("'useExistingScheduler' was configured to 'true', but we did not find any bean.");
}
if (taskScheduler != null) {
log.info("register existing TaskScheduler");
taskRegistrar.setScheduler(taskScheduler);
} else {
throw new BeanCreationException("Expecting a 'ConcurrentTaskScheduler' injected, but was 'null'");
}
} else {
log.info("'CustomSchedulingConfiguration' is disabled, create a default - 'ConcurrentTaskScheduler'");
this.localExecutor = Executors.newSingleThreadScheduledExecutor();
taskRegistrar.setScheduler(new ConcurrentTaskScheduler(localExecutor));
}
}
示例3: doTestWrapperTokenCreated
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
private void doTestWrapperTokenCreated(String authMountPath) {
final ClientHttpRequestFactory factory = createClientHttpRequestFactory();
final VaultTemplate template = new VaultTemplate(getVault().getEndpoint(), factory, () -> VaultToken.of(getVault().getToken()));
// Ensure approle auth enabled
template.opsForSys().authMount(authMountPath, VaultMount.create("approle"));
then(template.opsForSys().getAuthMounts()).containsKey(authMountPath + "/");
template.write("auth/" + authMountPath + "/role/testrole", CollectionsUtil.asMap(
"secret_id_ttl", "10m",
"token_num_uses", "10",
"token_ttl", "20m",
"token_max_ttl", "30m",
"secret_id_num_uses", "40"
));
Pair<String, String> credentials = getAppRoleCredentials(template, "auth/" + authMountPath + "/role/testrole");
final Pair<String, String> wrapped = VaultConnector.doRequestWrappedToken(new VaultFeatureSettings(getVault().getUrl(), authMountPath, credentials.getFirst(), credentials.getSecond()));
then(wrapped.getFirst()).isNotNull();
then(wrapped.getSecond()).isNotNull();
final CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions.builder()
.wrapped()
.initialToken(VaultToken.of(wrapped.getFirst()))
.build();
final RestTemplate simpleTemplate = UtilKt.createRestTemplate(new VaultFeatureSettings(getVault().getUrl(), authMountPath, "", ""));
final CubbyholeAuthentication authentication = new CubbyholeAuthentication(options, simpleTemplate);
final TaskScheduler scheduler = new ConcurrentTaskScheduler();
final MyLifecycleAwareSessionManager sessionManager = new MyLifecycleAwareSessionManager(authentication, simpleTemplate, scheduler);
then(sessionManager.getSessionToken()).isNotNull();
sessionManager.renewToken();
then(sessionManager.getSessionToken()).isNotNull();
}
示例4: setScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
/**
* Set the {@link TaskScheduler} to register scheduled tasks with, or a
* {@link java.util.concurrent.ScheduledExecutorService} to be wrapped as a
* {@code TaskScheduler}.
*/
public void setScheduler(Object scheduler) {
Assert.notNull(scheduler, "Scheduler object must not be null");
if (scheduler instanceof TaskScheduler) {
this.taskScheduler = (TaskScheduler) scheduler;
}
else if (scheduler instanceof ScheduledExecutorService) {
this.taskScheduler = new ConcurrentTaskScheduler(((ScheduledExecutorService) scheduler));
}
else {
throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getClass());
}
}
示例5: testReconnectDetailsSetServerAvailableAtStartup
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Test
public void testReconnectDetailsSetServerAvailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
// simulate a lost connection
CRUSHER_PROXY.reopen();
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1100);
Assert.assertTrue(service.isStarted());
Assert.assertTrue(service.isConnected());
Assert.assertEquals(2, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(1, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例6: testReconnectDetailsSetServerUnavailableAtStartup
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Test
public void testReconnectDetailsSetServerUnavailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
CRUSHER_PROXY.close();
TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
Assert.assertFalse(service.start());
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
CRUSHER_PROXY.open();
Thread.sleep(3100);
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(1, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例7: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Bean(name = DEFAULT_TASK_SCHEDULER_BEAN_NAME)
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TaskScheduler taskScheduler() {
if (taskExecutor != null) {
log.debug("create task-scheduler with pre-configured executor ...");
return new ConcurrentTaskScheduler(taskExecutor, scheduledExecutorService());
} else {
log.debug("create task-scheduler without pre-configured executor ...");
return new ConcurrentTaskScheduler(scheduledExecutorService());
}
}
示例8: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Bean(name="hapiJpaTaskExecutor")
public AsyncTaskExecutor taskScheduler() {
ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler();
retVal.setConcurrentExecutor(scheduledExecutorService().getObject());
retVal.setScheduledExecutor(scheduledExecutorService().getObject());
return retVal;
}
示例9: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Bean(name=TASK_EXECUTOR_NAME)
public TaskScheduler taskScheduler() {
ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler();
retVal.setConcurrentExecutor(scheduledExecutorService().getObject());
retVal.setScheduledExecutor(scheduledExecutorService().getObject());
return retVal;
}
示例10: CronChangeFinder
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
public CronChangeFinder() {
this.currentCron = getCronFromDB();
this.scheduler = new ConcurrentTaskScheduler();
this.task = new BizRunnable(this);
this.futrue = this.scheduler.schedule(this.task, new CronTrigger(this.currentCron));
}
示例11: main
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ConcurrentTaskScheduler scheduler = new ConcurrentTaskScheduler();
scheduler.schedule(new Runnable() {
@Override
public void run() {
System.out.println("test");
}
}, new CronTrigger("0/1 * * * * ?"));//3秒一次
System.in.read();
}
示例12: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Bean
TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler(threadPool());
}
示例13: withExecutorService
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Override
public ScheduledLockConfigurationBuilderWithoutDefaultLockAtMostFor withExecutorService(ScheduledExecutorService scheduledExecutorService) {
this.taskScheduler = new ConcurrentTaskScheduler(scheduledExecutorService);
return this;
}
示例14: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
@Bean(name = DEFAULT_TASK_SCHEDULER_BEAN_NAME)
@ConditionalOnMissingBean(name = DEFAULT_TASK_SCHEDULER_BEAN_NAME)
public TaskScheduler taskScheduler(final ScheduledExecutorService taskSchedulerService, final Tracer tracer) {
return new ConcurrentTaskScheduler(manage(taskSchedulerService, tracer));
}
示例15: taskScheduler
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; //导入依赖的package包/类
/**
* @return {@link TaskScheduler} for task execution
*/
@Bean
@ConditionalOnMissingBean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler(scheduledExecutorService());
}