Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Remove ConcurentTaskScheduler (See spring-projects/spring-statemachin…
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrouand committed Nov 29, 2022
1 parent 81f47a7 commit d31b868
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
39 changes: 36 additions & 3 deletions server/src/main/java/com/chutneytesting/ServerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.task.TaskExecutorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.task.support.ExecutorServiceAdapter;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@SpringBootApplication(exclude = {LiquibaseAutoConfiguration.class, ActiveMQAutoConfiguration.class, MongoAutoConfiguration.class})
@EnableScheduling
Expand Down Expand Up @@ -103,23 +107,49 @@ public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
};
}

/**
* Default task scheduler for
* With a default ScheduledExecutorService with a pool size of 1
*/
@Bean
public TaskScheduler taskScheduler() {
return new ThreadPoolTaskScheduler();
}

/**
* Default task executor for @Aync (used for SSE for example)
* With a default with default configuration: org.springframework.boot.autoconfigure.task.TaskExecutionProperties.Pool
*/
@Bean
public TaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
return builder.threadNamePrefix("app-task-exec").build();
}

/**
* For com.chutneytesting.execution.domain.schedule.CampaignScheduler#executeScheduledCampaigns()
*/
@Bean
public TaskExecutor scheduleCampaignsExecutor() {
return new SimpleAsyncTaskExecutor("schedule-campaigns-executor");
}

/**
* For com.chutneytesting.ServerConfiguration#executionConfiguration()
*/
@Bean
public TaskExecutor engineExecutor(@Value(ENGINE_THREAD_SPRING_VALUE) Integer threadForEngine) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(threadForEngine);
executor.setMaxPoolSize(threadForEngine);

executor.setThreadNamePrefix("engine-executor");
executor.initialize();
LOGGER.debug("Pool for engine created with size {}", threadForEngine);
return executor;
}

/**
* For com.chutneytesting.ServerConfiguration#campaignExecutionEngine()
*/
@Bean
public TaskExecutor campaignExecutor(@Value(CAMPAIGNS_THREAD_SPRING_VALUE) Integer threadForCampaigns) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand All @@ -131,6 +161,9 @@ public TaskExecutor campaignExecutor(@Value(CAMPAIGNS_THREAD_SPRING_VALUE) Integ
return executor;
}

/**
* For com.chutneytesting.execution.domain.schedule.CampaignScheduler#CampaignScheduler()
*/
@Bean
public ExecutorService scheduledCampaignsExecutor(@Value(SCHEDULED_CAMPAIGNS_THREAD_SPRING_VALUE) Integer threadForScheduledCampaigns) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
Expand All @@ -145,7 +178,7 @@ public ExecutorService scheduledCampaignsExecutor(@Value(SCHEDULED_CAMPAIGNS_THR
@Bean
public ExecutionConfiguration executionConfiguration(
@Value(ENGINE_REPORTER_PUBLISHER_TTL_SPRING_VALUE) Long reporterTTL,
Executor engineExecutor,
@Qualifier("engineExecutor") TaskExecutor engineExecutor,
@Value(TASK_SQL_NB_LOGGED_ROW) String nbLoggedRow,
@Value(ENGINE_DELEGATION_USER_SPRING_VALUE) String delegateUser,
@Value(ENGINE_DELEGATION_PASSWORD_SPRING_VALUE) String delegatePasword
Expand Down Expand Up @@ -206,7 +239,7 @@ CampaignExecutionEngine campaignExecutionEngine(CampaignRepository campaignRepos
DataSetHistoryRepository dataSetHistoryRepository,
JiraXrayEmbeddedApi jiraXrayEmbeddedApi,
ChutneyMetrics metrics,
TaskExecutor campaignExecutor,
@Qualifier("campaignExecutor") TaskExecutor campaignExecutor,
ObjectMapper objectMapper) {
return new CampaignExecutionEngine(
campaignRepository,
Expand Down
13 changes: 1 addition & 12 deletions server/src/main/java/com/chutneytesting/WebConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,12 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

@Configuration
public class WebConfiguration {

@Bean
@Primary // Because of https://github.com/spring-projects/spring-boot/issues/20308
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}

@Bean
public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
return builder.threadNamePrefix("app-task-exec").build();
}

@Bean
@Primary
public ObjectMapper objectMapper() {
Expand Down

0 comments on commit d31b868

Please sign in to comment.