org.springframework.core.task.SimpleAsyncTaskExecutor Java Examples

The following examples show how to use org.springframework.core.task.SimpleAsyncTaskExecutor. 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: WebAsyncManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void logExecutorWarning() {
	if (taskExecutorWarning && logger.isWarnEnabled()) {
		synchronized (DEFAULT_TASK_EXECUTOR) {
			AsyncTaskExecutor executor = this.taskExecutor;
			if (taskExecutorWarning &&
					(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor)) {
				String executorTypeName = executor.getClass().getSimpleName();
				logger.warn("\n!!!\n" +
						"An Executor is required to handle java.util.concurrent.Callable return values.\n" +
						"Please, configure a TaskExecutor in the MVC config under \"async support\".\n" +
						"The " + executorTypeName + " currently in use is not suitable under load.\n" +
						"-------------------------------\n" +
						"Request URI: '" + formatRequestUri() + "'\n" +
						"!!!");
				taskExecutorWarning = false;
			}
		}
	}
}
 
Example #2
Source File: WebAsyncManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void logExecutorWarning() {
	if (taskExecutorWarning && logger.isWarnEnabled()) {
		synchronized (DEFAULT_TASK_EXECUTOR) {
			AsyncTaskExecutor executor = this.taskExecutor;
			if (taskExecutorWarning &&
					(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor)) {
				String executorTypeName = executor.getClass().getSimpleName();
				logger.warn("\n!!!\n" +
						"An Executor is required to handle java.util.concurrent.Callable return values.\n" +
						"Please, configure a TaskExecutor in the MVC config under \"async support\".\n" +
						"The " + executorTypeName + " currently in use is not suitable under load.\n" +
						"-------------------------------\n" +
						"Request URI: '" + formatRequestUri() + "'\n" +
						"!!!");
				taskExecutorWarning = false;
			}
		}
	}
}
 
Example #3
Source File: AsyncExecutorConfiguration.java    From booties with Apache License 2.0 6 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    if (properties.isEnabled()) {
        ThreadPoolTaskExecutor executor = null;
        try {
            executor = beanFactory.getBean(ThreadPoolTaskExecutor.class);
        } catch (NoUniqueBeanDefinitionException e) {
            executor = beanFactory.getBean(DEFAULT_TASK_EXECUTOR_BEAN_NAME, ThreadPoolTaskExecutor.class);
        } catch (NoSuchBeanDefinitionException ex) {
        }
        if (executor != null) {
            log.info("use default TaskExecutor ...");
            return executor;
        } else {
            throw new BeanCreationException("Expecting a 'ThreadPoolTaskExecutor' exists, but was 'null'");
        }
    } else {
        log.info(
                "'AsyncExecutorConfiguration' is disabled, so create 'SimpleAsyncTaskExecutor' with 'threadNamePrefix' - '{}'",
                properties.getThreadNamePrefix());
        return new SimpleAsyncTaskExecutor(properties.getThreadNamePrefix());
    }
}
 
Example #4
Source File: AppConfig.java    From flow-platform-x with Apache License 2.0 6 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster() {

        @Override
        public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
            if (event instanceof SyncEvent) {
                ResolvableType type = (eventType != null ? eventType : ResolvableType.forInstance(event));
                for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) {
                    invokeListener(listener, event);
                }
                return;
            }

            super.multicastEvent(event, eventType);
        }
    };

    SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("s-event-");
    multicaster.setTaskExecutor(executor);
    return multicaster;
}
 
Example #5
Source File: StandardWebSocketClientTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #6
Source File: AsynchronousSpringEventsConfiguration.java    From integration-patterns with MIT License 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    final SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();

    // FIXME use fixed size thread pool
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #7
Source File: AsynchronousSpringEventsConfig.java    From wetech-admin with MIT License 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster
            = new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #8
Source File: SettleJobConfiguration.java    From seed with Apache License 2.0 5 votes vote down vote up
private Flow splitFlow(){
    Flow flow04 = new FlowBuilder<SimpleFlow>("flow04").start(step0004).build();
    Flow flow05 = new FlowBuilder<SimpleFlow>("flow05").start(step0005).build();
    Flow flow06 = new FlowBuilder<SimpleFlow>("flow06").start(step0006).build();
    return new FlowBuilder<SimpleFlow>("splitFlow")
            .split(new SimpleAsyncTaskExecutor("springbatch_seedboot"))
            .add(flow04, flow05, flow06)
            .build();
}
 
Example #9
Source File: SplitJobDemo.java    From SpringAll with MIT License 5 votes vote down vote up
@Bean
public Job splitJob() {
    return jobBuilderFactory.get("splitJob")
            .start(flow1())
            .split(new SimpleAsyncTaskExecutor()).add(flow2())
            .end()
            .build();

}
 
Example #10
Source File: Application.java    From daming with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster
            = new SimpleApplicationEventMulticaster();

    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #11
Source File: AdHocStarter.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
public AdHocStarter(JobLocator jobLocator, JobRepository jobRepository, JobPropertyResolvers jobPropertyResolvers,
                    @Value("${com.github.chrisgleissner.springbatchrest.addUniqueJobParameter:true}") boolean addUniqueJobParameter,
                    JobRegistry jobRegistry) {
    this.jobLocator = jobLocator;
    asyncJobLauncher = jobLauncher(new SimpleAsyncTaskExecutor(), jobRepository);
    syncJobLauncher = jobLauncher(new SyncTaskExecutor(), jobRepository);
    this.jobPropertyResolvers = jobPropertyResolvers;
    this.addUniqueJobParameter = addUniqueJobParameter;
    this.jobRegistry = jobRegistry;
    log.info("Adding unique job parameter: {}", addUniqueJobParameter);
}
 
Example #12
Source File: JobTaskScheduled.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
public void run() {
    long timeCount = count.incrementAndGet();
    log.info("任务执行开始 [count={}, date={}]",timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()));
    SimpleJobLauncher launcher = new SimpleJobLauncher();
    launcher.setJobRepository(jobRepository);
    launcher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    try {
        launcher.run(batchJob, new JobParameters());
    } catch (Exception e) {
        log.error("任务执行失败 [count={}, date={}]", timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()),e);
    } finally {
        log.info("任务执行结束 [count={}, date={}]",timeCount, DateFormatUtil.formatDate(DateFormatUtil.PATTERN_DEFAULT_ON_SECOND, new Date()));
    }

}
 
Example #13
Source File: NotificationEventBusConfig.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #14
Source File: NotificationEventListenerKafkaIntegrationTest.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #15
Source File: NotificationEventListenerTest.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
  SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();
  eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());

  return eventMulticaster;
}
 
Example #16
Source File: ButlerConfig.java    From cf-butler with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster =
        new SimpleApplicationEventMulticaster();
    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #17
Source File: BufferedSimpleAsyncHttpRequestFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected AsyncClientHttpRequestFactory createRequestFactory() {
	SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
	AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
	requestFactory.setTaskExecutor(taskExecutor);
	return requestFactory;
}
 
Example #18
Source File: JobConfiguration.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
@Bean
    @Qualifier("slaveTaskExecutor")
    public TaskExecutor taskExecutor() {
//        ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
//        exec.setMaxPoolSize(Integer.parseInt(env.getProperty("concurrencyLimit")));
        SimpleAsyncTaskExecutor exec = new SimpleAsyncTaskExecutor();
        exec.setConcurrencyLimit(concurrencyLimit);
        return exec;
    }
 
Example #19
Source File: ReactiveTypeHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
	Assert.notNull(registry, "ReactiveAdapterRegistry is required");
	Assert.notNull(executor, "TaskExecutor is required");
	Assert.notNull(manager, "ContentNegotiationManager is required");
	this.adapterRegistry = registry;
	this.taskExecutor = executor;
	this.contentNegotiationManager = manager;

	this.taskExecutorWarning =
			(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor);
}
 
Example #20
Source File: StandardWebSocketClientTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: JettyWebSocketClientTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #22
Source File: BufferedSimpleAsyncHttpRequestFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected AsyncClientHttpRequestFactory createRequestFactory() {
	SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
	AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
	requestFactory.setTaskExecutor(taskExecutor);
	return requestFactory;
}
 
Example #23
Source File: AsyncSpringLiquibaseTest.java    From jhipster with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
    executor = new SimpleAsyncTaskExecutor();
    recorder = LogbackRecorder.forClass(MockEnvironment.class).reset().capture("ALL");
    environment = new MockEnvironment();
    recorder.release();
    config = spy(new TestAsyncSpringLiquibase(executor, environment));
    recorder = LogbackRecorder.forClass(AsyncSpringLiquibase.class).reset().capture("ALL");
}
 
Example #24
Source File: SpringBatchLightminBatchConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean(name = "defaultAsyncJobLauncher")
public JobLauncher defaultAsyncJobLauncher(final JobRepository jobRepository) {
    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return jobLauncher;
}
 
Example #25
Source File: GH1212Tests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
public AsyncConfigurer customAsyncConfigurer() {
	return new AsyncConfigurerSupport() {
		@Override
		public Executor getAsyncExecutor() {
			return new SimpleAsyncTaskExecutor("customAsyncConfigurer");
		}
	};
}
 
Example #26
Source File: CSVSerializerTest.java    From data-prep with Apache License 2.0 5 votes vote down vote up
public CSVSerializerTest() {
    this.serializer = new CSVSerializer();
    TaskExecutor executor = new SimpleAsyncTaskExecutor();
    ReflectionTestUtils.setField(serializer, "executor", executor);
    ReflectionTestUtils.setField(serializer, "defaultTextEnclosure", "\"");
    ReflectionTestUtils.setField(serializer, "defaultEscapeChar", "\u0000");

}
 
Example #27
Source File: AsynchronousSpringEventConfiguration.java    From data-prep with Apache License 2.0 5 votes vote down vote up
@Bean(name = "applicationEventMulticaster")
public ApplicationEventMulticaster simpleApplicationEventMulticaster() {
    SimpleApplicationEventMulticaster eventMulticaster = new SimpleApplicationEventMulticaster();

    eventMulticaster.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return eventMulticaster;
}
 
Example #28
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testCustomTaskExecutor() throws Exception {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
	container.setTaskExecutor(taskExecutor);

	container.setAmazonSqs(mock(AmazonSQSAsync.class, withSettings().stubOnly()));
	container.setMessageHandler(mock(QueueMessageHandler.class));
	container.setBeanName("testContainerName");
	container.afterPropertiesSet();

	assertThat(container.getTaskExecutor()).isEqualTo(taskExecutor);
}
 
Example #29
Source File: SimpleMessageListenerContainerTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testContainerDoesNotProcessMessageAfterBeingStopped() throws Exception {
	SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
	SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
	container.setTaskExecutor(taskExecutor);

	AmazonSQSAsync sqs = mock(AmazonSQSAsync.class, withSettings().stubOnly());
	container.setAmazonSqs(sqs);

	QueueMessageHandler messageHandler = new QueueMessageHandler() {

		@Override
		public void handleMessage(org.springframework.messaging.Message<?> message)
				throws MessagingException {
			fail("Should not have been called");
		}
	};
	container.setMessageHandler(messageHandler);
	container.setBeanName("testContainerName");

	mockGetQueueUrl(sqs, "testQueue",
			"http://testContainerDoesNotProcessMessageAfterBeingStopped.amazonaws.com");

	container.afterPropertiesSet();

	when(sqs.receiveMessage(new ReceiveMessageRequest(
			"http://testContainerDoesNotProcessMessageAfterBeingStopped.amazonaws.com")))
					.thenAnswer((Answer<ReceiveMessageResult>) invocation -> {
						container.stop();
						return new ReceiveMessageResult()
								.withMessages(new Message().withBody("test"));
					});

	container.start();
}
 
Example #30
Source File: JpaBatchConfigurer.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
private JobLauncher createJobLauncher() throws Exception {
	SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
	jobLauncher.setJobRepository(jobRepository);
	jobLauncher.setTaskExecutor( new SimpleAsyncTaskExecutor());
	jobLauncher.afterPropertiesSet();
	return jobLauncher;
}