| | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * Created by vincent on 11/9/2024 |
| | |
| | | if (null == this.executorService) { |
| | | int count = agvList.size(); |
| | | this.executorService = Executors.newFixedThreadPool(count); |
| | | log.info("Initialized ExecutorService with {} threads.", count); |
| | | } |
| | | |
| | | this.responseTheRequest(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void shutdownExecutorService() { |
| | | if (this.executorService != null && !executorService.isShutdown()) { |
| | | log.info("Shutting down ExecutorService."); |
| | | executorService.shutdown(); |
| | | try { |
| | | if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { |
| | | log.warn("ExecutorService did not terminate in the specified time."); |
| | | executorService.shutdownNow(); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | log.error("Interrupted while waiting for ExecutorService to terminate.", e); |
| | | executorService.shutdownNow(); |
| | | Thread.currentThread().interrupt(); |
| | | } finally { |
| | | this.executorService = null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |