Dann rufen Sie threadPoolTaskExecutor.getThreadPoolExecutor().hashCode() auf, um den neuesten hasCode zu erhalten.
Code: Select all
@Slf4j
@EnableAsync
@Configuration
public class AsyncConfig {
@Bean
public ThreadPoolTaskExecutor taskExecutor(ThreadPoolTaskExecutorBuilder builder) {
// init
ThreadPoolTaskExecutor threadPoolTaskExecutor = AsyncConfigUtil.createThreadPoolTaskExecutor("DefaultAsync-", builder);
ThreadPoolExecutor threadPoolExecutor = threadPoolTaskExecutor.getThreadPoolExecutor();
log.info("getThreadPoolExecutor().hashCode():{} class:{}", System.identityHashCode(threadPoolExecutor),threadPoolExecutor.getClass());
return threadPoolTaskExecutor;
}
}
Code: Select all
@Slf4j
public class ThreadPoolAutoRegistration implements BeanPostProcessor {
@Override
public @Nullable Object postProcessAfterInitialization(@Nullable Object bean, @Nullable String beanName)
throws BeansException {
// Auto Registration ThreadPoolTaskExecutor
if (bean instanceof ThreadPoolTaskExecutor taskExecutor) {
ThreadPoolExecutor threadPoolExecutor = taskExecutor.getThreadPoolExecutor();
log.info("getThreadPoolExecutor().hashCode():{} class:{}", System.identityHashCode(threadPoolExecutor),threadPoolExecutor.getClass());
GracefulShutdownMonitorConfig.registerThreadPool(
beanName + "-" + taskExecutor.getThreadNamePrefix(),
taskExecutor.getThreadPoolExecutor()
);
}
return bean;
}
}
Code: Select all
2026-01-13 14:33:51.714 INFO 56464 --- [ main][] com.zhiwandian.config.AsyncConfig : getThreadPoolExecutor().hashCode():271306390 class:class org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor$1
2026-01-13 14:33:51.727 INFO 56464 --- [ main][] c.zhiwandian.ThreadPoolAutoRegistration : getThreadPoolExecutor().hashCode():2079009730 class:class org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor$1
Ich habe den Quellcode von initializeExecutor überprüft und an keiner anderen Stelle wurde der Executor neu initialisiert.
Welche Umstände unterscheiden sie?
Mobile version