Spring Boot configures @KafkaListener
s on virtual threads if they are enabled (KafkaAnnotationDrivenConfiguration), but monitoring of non-responsive consumer still works on platform thread https://github.com/spring-projects/spring-kafka/blob/v4.0.0-M5/spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java#L940
Is it worth configuring TaskScheduler on virtual threads in this case also?
Comment From: artembilan
That scheduled task is doing this:
protected void checkConsumer() {
long timeSinceLastPoll = System.currentTimeMillis() - this.lastPoll;
if (((float) timeSinceLastPoll) / (float) this.containerProperties.getPollTimeout()
> this.containerProperties.getNoPollThreshold()) {
publishNonResponsiveConsumerEvent(timeSinceLastPoll, this.consumer);
}
}
So, unless you doing something heavy with that NonResponsiveConsumerEvent
handling I don't see any harm with platform thread.
You may go with a customizer bean to inject an auto-configured TaskScheduler
with virtual threads:
@Bean
ContainerCustomizer<Object, Object, ConcurrentMessageListenerContainer<Object, Object>> containerCustomizer(TaskScheduler scheduler) {
return container -> container.getContainerProperties().setScheduler(scheduler);
}
That TaskScheduler
is auto-configured in the: https://github.com/spring-projects/spring-boot/blob/main/core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskSchedulingConfigurations.java#L63-L67
Comment From: wilkinsona
Thanks, @artembilan. Based on that, I think we should leave things as they are. Thanks anyway for the suggestion, @ilia1243.
Comment From: ilia1243
I only meant a small optimization of memory consumption by this proposal. Thank you for quick response.