org.springframework.scheduling.concurrent.ConcurrentTaskScheduler Java Examples
The following examples show how to use
org.springframework.scheduling.concurrent.ConcurrentTaskScheduler.
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: ClusterSelectorManagedScriptIntegrationTest.java From genie with Apache License 2.0 | 6 votes |
@BeforeEach void setUp() { final MeterRegistry meterRegistry = new SimpleMeterRegistry(); final ScriptManagerProperties scriptManagerProperties = new ScriptManagerProperties(); final TaskScheduler taskScheduler = new ConcurrentTaskScheduler(); final ExecutorService executorService = Executors.newCachedThreadPool(); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ResourceLoader resourceLoader = new DefaultResourceLoader(); final ScriptManager scriptManager = new ScriptManager( scriptManagerProperties, taskScheduler, executorService, scriptEngineManager, resourceLoader, meterRegistry ); this.scriptProperties = new ClusterSelectorScriptProperties(); this.clusterSelectorScript = new ClusterSelectorManagedScript( scriptManager, this.scriptProperties, meterRegistry ); }
Example #2
Source File: ManagedScriptIntegrationTest.java From genie with Apache License 2.0 | 6 votes |
@BeforeEach void setUp() { final MeterRegistry meterRegistry = new SimpleMeterRegistry(); final ScriptManagerProperties scriptManagerProperties = new ScriptManagerProperties(); final TaskScheduler taskScheduler = new ConcurrentTaskScheduler(); final ExecutorService executorService = Executors.newCachedThreadPool(); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ResourceLoader resourceLoader = new DefaultResourceLoader(); this.objectMapper = GenieObjectMapper.getMapper(); final ScriptManager scriptManager = new ScriptManager( scriptManagerProperties, taskScheduler, executorService, scriptEngineManager, resourceLoader, meterRegistry ); this.scriptProperties = new TestScriptProperties(); this.script = new TestScript( scriptManager, this.scriptProperties, meterRegistry ); }
Example #3
Source File: ExecutionModeFilterScriptIntegrationTest.java From genie with Apache License 2.0 | 6 votes |
@BeforeEach void setUp() { final MeterRegistry meterRegistry = new SimpleMeterRegistry(); final ScriptManagerProperties scriptManagerProperties = new ScriptManagerProperties(); final TaskScheduler taskScheduler = new ConcurrentTaskScheduler(); final ExecutorService executorService = Executors.newCachedThreadPool(); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ResourceLoader resourceLoader = new DefaultResourceLoader(); final ObjectMapper objectMapper = GenieObjectMapper.getMapper(); final ScriptManager scriptManager = new ScriptManager( scriptManagerProperties, taskScheduler, executorService, scriptEngineManager, resourceLoader, meterRegistry ); this.scriptProperties = new ExecutionModeFilterScriptProperties(); this.executionModeFilterScript = new ExecutionModeFilterScript( scriptManager, scriptProperties, objectMapper, meterRegistry ); }
Example #4
Source File: ServiceClient.java From spring-boot-websocket-client with MIT License | 6 votes |
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. }
Example #5
Source File: CommandSelectorManagedScriptIntegrationTest.java From genie with Apache License 2.0 | 6 votes |
@BeforeEach void setUp() { this.meterRegistry = new SimpleMeterRegistry(); this.executorService = Executors.newCachedThreadPool(); final ScriptManager scriptManager = new ScriptManager( new ScriptManagerProperties(), new ConcurrentTaskScheduler(), this.executorService, new ScriptEngineManager(), new DefaultResourceLoader(), this.meterRegistry ); this.scriptProperties = new CommandSelectorManagedScriptProperties(); this.commandSelectorManagedScript = new CommandSelectorManagedScript( scriptManager, this.scriptProperties, this.meterRegistry ); }
Example #6
Source File: CustomSchedulingConfiguration.java From booties with Apache License 2.0 | 6 votes |
@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)); } }
Example #7
Source File: RegisterDefaultTaskSchedulerPostProcessor.java From ShedLock with Apache License 2.0 | 6 votes |
@Override public void postProcessBeanDefinitionRegistry(@NonNull BeanDefinitionRegistry registry) throws BeansException { ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory; if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(listableBeanFactory, TaskScheduler.class).length == 0) { String[] scheduledExecutorsBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(listableBeanFactory, ScheduledExecutorService.class); if (scheduledExecutorsBeanNames.length != 1) { logger.debug("Registering default TaskScheduler"); registry.registerBeanDefinition(DEFAULT_TASK_SCHEDULER_BEAN_NAME, rootBeanDefinition(ConcurrentTaskScheduler.class).getBeanDefinition()); if (scheduledExecutorsBeanNames.length != 0) { logger.warn("Multiple ScheduledExecutorService found, do not know which one to use."); } } else { logger.debug("Registering default TaskScheduler with existing ScheduledExecutorService {}", scheduledExecutorsBeanNames[0]); registry.registerBeanDefinition(DEFAULT_TASK_SCHEDULER_BEAN_NAME, rootBeanDefinition(ConcurrentTaskScheduler.class) .addPropertyReference("scheduledExecutor", scheduledExecutorsBeanNames[0]) .getBeanDefinition() ); } } }
Example #8
Source File: ScheduledTaskRegistrar.java From spring-analysis-note with MIT License | 5 votes |
/** * 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(@Nullable Object scheduler) { if (scheduler == null) { this.taskScheduler = null; } else 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()); } }
Example #9
Source File: ScheduledTaskConfigurationTest.java From bugsnag-java with MIT License | 5 votes |
@Test public void findExecutorByName() throws NoSuchFieldException, IllegalAccessException { ScheduledExecutorService expected = Executors.newScheduledThreadPool(4); Throwable exc = new NoUniqueBeanDefinitionException(ScheduledExecutorService.class); when(context.getBean(ScheduledExecutorService.class)).thenThrow(exc); when(context.getBean("taskScheduler", ScheduledExecutorService.class)) .thenReturn(expected); configuration.configureTasks(registrar); TaskScheduler scheduler = registrar.getScheduler(); assertTrue(scheduler instanceof ConcurrentTaskScheduler); assertEquals(expected, accessField(scheduler, "scheduledExecutor")); }
Example #10
Source File: ScheduledTaskConfigurationTest.java From bugsnag-java with MIT License | 5 votes |
@Test public void findExecutorByType() throws NoSuchFieldException, IllegalAccessException { ScheduledExecutorService expected = Executors.newScheduledThreadPool(1); when(context.getBean(ScheduledExecutorService.class)).thenReturn(expected); configuration.configureTasks(registrar); TaskScheduler scheduler = registrar.getScheduler(); assertTrue(scheduler instanceof ConcurrentTaskScheduler); assertEquals(expected, accessField(scheduler, "scheduledExecutor")); }
Example #11
Source File: CustomSchedulingConfiguration.java From booties with Apache License 2.0 | 5 votes |
@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()); } }
Example #12
Source File: ScheduledTaskRegistrar.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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()); } }
Example #13
Source File: ScheduledTaskRegistrar.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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()); } }
Example #14
Source File: ScheduledTaskRegistrar.java From java-technology-stack with MIT License | 5 votes |
/** * 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(@Nullable Object scheduler) { if (scheduler == null) { this.taskScheduler = null; } else 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()); } }
Example #15
Source File: LightminClientApplicationRegistrationService.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
public LightminClientApplicationRegistrationService(final LightminClientRegistratorService lightminClientRegistrator, final ScheduledExecutorService scheduler) { this(lightminClientRegistrator, new ConcurrentTaskScheduler(scheduler)); }
Example #16
Source File: ExecutorAutoConfiguration.java From hawkbit with Eclipse Public License 1.0 | 4 votes |
/** * @return {@link TaskScheduler} for task execution */ @Bean @ConditionalOnMissingBean public TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(scheduledExecutorService()); }
Example #17
Source File: DeviceSimulator.java From hawkbit-examples with Eclipse Public License 1.0 | 4 votes |
@Bean TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(threadPool()); }
Example #18
Source File: ResourceConfig.java From halyard with Apache License 2.0 | 4 votes |
@Bean TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(Executors.newSingleThreadScheduledExecutor()); }
Example #19
Source File: Spring4WebSocketExamplesApplication.java From spring4ws-demos with Apache License 2.0 | 4 votes |
@Override public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { taskRegistrar.setTaskScheduler(new ConcurrentTaskScheduler( Executors.newSingleThreadScheduledExecutor())); }
Example #20
Source File: BatchConfiguration.java From Software-Architecture-with-Spring-5.0 with MIT License | 4 votes |
@Bean public TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(); }
Example #21
Source File: WebSocketConfiguration.java From data-highway with Apache License 2.0 | 4 votes |
@Bean public TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(Executors.newSingleThreadScheduledExecutor()); }