以下是我对Executor的配置
@Configuration @EnableAsync public class AsyncServiceExecutorConfig extends AsyncConfigurerSupport { @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(xxx.getCorePoolSize()); executor.setMaxPoolSize(xxx.getMaxPoolSize()); executor.setQueueCapacity(xxx.getQueueCapacity()); executor.setThreadNamePrefix("MyAsync-"); executor.initialize(); return executor; } } Executor executor = asyncExecutorConfig.getAsyncExecutor(); CompletableFuture.runAsync(() -> { }, executor);
当我打印出线程名时,它们都以MyAsync-1结尾
我在一个MyAsync-1中设置了Thread.sleep。下一个新线程仍然显示为MyAsync-1
我做错什么了吗?为什么它不给我MyAsync-2、MyAsync-3等