diff --git a/src/main/java/club/joylink/rtss/configuration/TaskExecutorConfiguration.java b/src/main/java/club/joylink/rtss/configuration/TaskExecutorConfiguration.java new file mode 100644 index 000000000..7e7c7fcd1 --- /dev/null +++ b/src/main/java/club/joylink/rtss/configuration/TaskExecutorConfiguration.java @@ -0,0 +1,103 @@ +package club.joylink.rtss.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; + +import java.util.concurrent.ThreadPoolExecutor; + +@Configuration +@EnableAsync +public class TaskExecutorConfiguration { + /*** + * 创建仿真异步逻辑执行线程池 + * @return + */ + @Bean("simulationExecutor") + public TaskExecutor simulationExecutor(Environment env) { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setThreadNamePrefix("simulation-executor-"); + taskExecutor.setCorePoolSize(1); + taskExecutor.setMaxPoolSize(1); + taskExecutor.setQueueCapacity(10); + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.initialize(); + return taskExecutor; + } + + /*** + * 创建新仿真异步逻辑执行线程池 + * @return + */ + @Bean("nsExecutor") + public TaskExecutor nsExecutor(Environment env) { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setThreadNamePrefix("ns-executor-"); + taskExecutor.setCorePoolSize(2); + taskExecutor.setMaxPoolSize(2); + taskExecutor.setQueueCapacity(100); + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.initialize(); + return taskExecutor; + } + + /*** + * 创建新仿真异步逻辑执行线程池 + * @return + */ + @Bean("realDeviceExecutor") + public TaskExecutor realDeviceExecutor(Environment env) { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setThreadNamePrefix("real-device-executor-"); + taskExecutor.setCorePoolSize(1); + taskExecutor.setMaxPoolSize(1); + taskExecutor.setQueueCapacity(100); + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.initialize(); + return taskExecutor; + } + + /*** + * 异步逻辑执行线程池 + * @return + */ + @Bean("commonExecutor") + public TaskExecutor commonExecutor(Environment env) { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setThreadNamePrefix("common-executor-"); + taskExecutor.setMaxPoolSize(20); + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.initialize(); + return taskExecutor; + } + + + + /**定时任务调度器*/ + @Bean("scheduler") + public ThreadPoolTaskScheduler threadPoolTaskScheduler(){ + return new ThreadPoolTaskScheduler(); + + } + + /*** + * 创建仿真UDP数据处理执行线程池 + * @return + */ + @Bean("socketExecutor") + public TaskExecutor socketExecutor(Environment env) { + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); + taskExecutor.setThreadNamePrefix("socket-executor-"); + taskExecutor.setCorePoolSize(1); + taskExecutor.setMaxPoolSize(1); + taskExecutor.setQueueCapacity(10); + taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + taskExecutor.initialize(); + return taskExecutor; + } + +} diff --git a/src/main/java/club/joylink/rtss/services/voice/baidu/TokenHolder.java b/src/main/java/club/joylink/rtss/services/voice/baidu/TokenHolder.java index 5eced7740..cf4adae85 100644 --- a/src/main/java/club/joylink/rtss/services/voice/baidu/TokenHolder.java +++ b/src/main/java/club/joylink/rtss/services/voice/baidu/TokenHolder.java @@ -148,6 +148,6 @@ public class TokenHolder { throw new RuntimeException("scope not exist, " + scope + "," + result); } token = (String)map.get("access_token"); - expiresAt = System.currentTimeMillis() + ((Long)map.get("expires_in")) * 1000; + expiresAt = System.currentTimeMillis() + (Long.parseLong(map.get("expires_in").toString())) * 1000; } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java index 06ac70b1b..300c162a9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java @@ -600,7 +600,6 @@ public class SimulationMainThread { this.stompMessageService.sendToUser(userIds, message); } - @Order(1) @EventListener(SimulationConversationChatEvent.class) public void conversationChat(SimulationConversationChatEvent event) { Simulation simulation = event.getSimulation(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptListener.java b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptListener.java index e51b87342..ca4cb7430 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptListener.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptListener.java @@ -1,8 +1,8 @@ package club.joylink.rtss.simulation.cbtc.competition; +import club.joylink.rtss.services.simulation.ScriptExecuteService; import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; import club.joylink.rtss.simulation.cbtc.event.*; -import club.joylink.rtss.services.simulation.ScriptExecuteService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; @@ -36,6 +36,7 @@ public class CompetitionAndScriptListener { } } + @Async("nsExecutor") @EventListener public void handle(SimulationConversationMemberConnectEvent event) { competitionAndScriptManager.try2FinishAcceptInvitationAction(event.getSimulation(), event.getMember());