5

I'm migrating a Spring Boot project to version 3. The project uses asynchronous task and tracing.

Following the documentation on Micrometer GitHub wiki, we tried to define the Async executor like that:

@Configuration(proxyBeanMethods = false)
@EnableAsync
class EventProcessingConfig {
  @Bean("eventsPublishExecutor")
  fun eventsPublishExecutor(): Executor {
     val executor =
          object : ThreadPoolTaskExecutor() {
            override fun initializeExecutor(
              threadFactory: ThreadFactory,
              rejectedExecutionHandler: RejectedExecutionHandler
            ): ExecutorService {
              val executorService = super.initializeExecutor(threadFactory,
     rejectedExecutionHandler)
              return ContextExecutorService.wrap(executorService, ContextSnapshot::captureAll)
            }
          }

        with(executor) {
          setThreadNamePrefix("processing-events-")
          setWaitForTasksToCompleteOnShutdown(true)
          setAwaitTerminationSeconds(30)
          initialize()
        }

        return executor

However, we still lose the tracing. And replacing the bean creation by the code below makes everything works as expected (without the customization though)

 return ContextExecutorService.wrap(
      Executors.newSingleThreadExecutor(),
      ContextSnapshot::captureAll
    )

Do you know what's wrong or missing in the first code with Spring Boot 3?

Ludovic Mouline
  • 163
  • 1
  • 6

0 Answers0