javaspring-boottomcatconcurrencyforkjoinpool

Can I configure parallelism of ForkJoinPool created for Tomcat in Spring Boot application?


Investigating the issue Spring Boot application gets stuck when virtual threads are used on Java 21 I found out that having virtual threads enabled in Spring Boot application its Tomcat will create ForkJoinPool with parallelism = 20. In fact this means there will be only 20 carrier threads that might cause issues when virtual threads got pinned.

So is there any property in Spring Boot allowing configuration of Tomcat's ForkJoinPool? I've tried

server:
  tomcat:
    threads:
      max: 110

but this doesn't help and seems to be working only for platform threads.


Solution

  • For now it looks like this cannot be configured via Spring Boot's application.yml. As far as I understand from debugging, the only way to do this is to specify -Djdk.virtualThreadScheduler.parallelism=n in JVM options.

    But this apparently would affect the whole application, not only one particular ForkJoinPool.