/** * Create a new instance of the {@code AsyncRestTemplate} using default settings. * <p>This constructor uses a {@link SimpleClientHttpRequestFactory} in combination * with a {@link SimpleAsyncTaskExecutor} for asynchronous execution. */ public AsyncRestTemplate() { this(new SimpleAsyncTaskExecutor()); }
/** * Create a new instance of the {@code AsyncRestTemplate} using default settings. * <p>This constructor uses a {@link SimpleClientHttpRequestFactory} in combination * with a {@link SimpleAsyncTaskExecutor} for asynchronous execution. */ public AsyncRestTemplate() { this(new SimpleAsyncTaskExecutor()); }
/** * Create a default TaskExecutor. Called if no explicit TaskExecutor has been specified. * <p>The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor} * with the specified bean name (or the class name, if no bean name specified) as thread name prefix. * @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String) */ protected TaskExecutor createDefaultTaskExecutor() { String beanName = getBeanName(); String threadNamePrefix = (beanName != null ? beanName + "-" : DEFAULT_THREAD_NAME_PREFIX); return new SimpleAsyncTaskExecutor(threadNamePrefix); }
@Bean @ConditionalOnMissingBean public TaskExecutor taskExecutor() { return new SimpleAsyncTaskExecutor(); }
/** * This implementation searches for a unique {@link org.springframework.core.task.TaskExecutor} * bean in the context, or for an {@link Executor} bean named "taskExecutor" otherwise. * If neither of the two is resolvable (e.g. if no {@code BeanFactory} was configured at all), * this implementation falls back to a newly created {@link SimpleAsyncTaskExecutor} instance * for local use if no default could be found. * @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME */ @Override @Nullable protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { Executor defaultExecutor = super.getDefaultExecutor(beanFactory); return (defaultExecutor != null ? defaultExecutor : new SimpleAsyncTaskExecutor()); }
@SuppressWarnings("deprecation") @Override protected AsyncClientHttpRequestFactory createRequestFactory() { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); requestFactory.setTaskExecutor(taskExecutor); return requestFactory; }
@Bean public AsyncTaskExecutor exec() { SimpleAsyncTaskExecutor simpleAsyncTaskExecutor = new SimpleAsyncTaskExecutor(); simpleAsyncTaskExecutor.setThreadNamePrefix("exec-"); return simpleAsyncTaskExecutor; }
@Test public void throttleIsNotActiveByDefault() throws Exception { SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); assertFalse("Concurrency throttle must not default to being active (on)", executor.isThrottleActive()); }
@Test public void throwsExceptionWhenSuppliedWithNullRunnable() throws Exception { exception.expect(IllegalArgumentException.class); new SimpleAsyncTaskExecutor().execute(null); }
@Before public void setup() { taskExecutor = new SimpleAsyncTaskExecutor(); writtenItems = new ArrayList<>(); writer = new AsyncItemWriter<>(); }
@Test public void taskExecutor() throws Exception { URI uri = new URI("ws://localhost/abc"); this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor()); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertNotNull(session); }
@Test public void threadFactoryOverridesDefaults() throws Exception { final Object monitor = new Object(); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "test"); } }); ThreadNameHarvester task = new ThreadNameHarvester(monitor); executeAndWait(executor, task, monitor); assertEquals("test", task.getThreadName()); }
@Test public void threadNameGetsSetCorrectly() throws Exception { final String customPrefix = "chankPop#"; final Object monitor = new Object(); SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(customPrefix); ThreadNameHarvester task = new ThreadNameHarvester(monitor); executeAndWait(executor, task, monitor); assertThat(task.getThreadName(), startsWith(customPrefix)); }
@Test public void doHandshakeWithTaskExecutor() throws Exception { WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); headers.setSecWebSocketProtocol(Arrays.asList("echo")); this.client.setTaskExecutor(new SimpleAsyncTaskExecutor()); this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get(); assertEquals(this.wsUrl, this.wsSession.getUri().toString()); assertEquals("echo", this.wsSession.getAcceptedProtocol()); }
@Test public void testConcurrentHandling() throws Exception { Flow flow1 = mock(Flow.class); Flow flow2 = mock(Flow.class); SplitState state = new SplitState(Arrays.asList(flow1, flow2), "foo"); state.setTaskExecutor(new SimpleAsyncTaskExecutor()); when(flow1.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); when(flow2.start(executor)).thenReturn(new FlowExecution("step1", FlowExecutionStatus.COMPLETED)); FlowExecutionStatus result = state.handle(executor); assertEquals(FlowExecutionStatus.COMPLETED, result); }
@Test public void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception { SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY); assertTrue(executor.isThrottleActive()); exception.expect(IllegalStateException.class); executor.execute(new NoOpRunnable()); }
@Test public void testSetTaskExecutor() throws Exception { handler.setTaskExecutor(new SimpleAsyncTaskExecutor()); handler.handle(stepExecutionSplitter, stepExecution); assertEquals(1, count); }
private void initializeTasklet() { tasklet = new SystemCommandTasklet(); tasklet.setEnvironmentParams(null); // inherit from parent process tasklet.setWorkingDirectory(null); // inherit from parent process tasklet.setSystemProcessExitCodeMapper(new SimpleSystemProcessExitCodeMapper()); tasklet.setTimeout(5000); // long enough timeout tasklet.setTerminationCheckInterval(500); tasklet.setCommand("invalid command, change value for successful execution"); tasklet.setInterruptOnCancel(true); tasklet.setTaskExecutor(new SimpleAsyncTaskExecutor()); }
@Test public void testBuildSplit_BATCH_2282() throws Exception { Flow flow1 = new FlowBuilder<Flow>("subflow1").from(step1).end(); Flow flow2 = new FlowBuilder<Flow>("subflow2").from(step2).end(); Flow splitFlow = new FlowBuilder<Flow>("splitflow").split(new SimpleAsyncTaskExecutor()).add(flow1, flow2).build(); FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(splitFlow).end(); builder.preventRestart().build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
@Test public void testBuildSplitUsingStartAndAdd_BATCH_2346() throws Exception { Flow subflow1 = new FlowBuilder<Flow>("subflow1").from(step2).end(); Flow subflow2 = new FlowBuilder<Flow>("subflow2").from(step3).end(); Flow splitflow = new FlowBuilder<Flow>("splitflow").start(subflow1).split(new SimpleAsyncTaskExecutor()) .add(subflow2).build(); FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(splitflow).end(); builder.preventRestart().build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }