Skip to content
Advertisement

How to log the number of available/used threads in a spring boot (tomcat) based application?

Is there a spring boot config where you can log the number of available/used threads the app server currently has?

Advertisement

Answer

You can use the actuator framework.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Then you have to enable tomcat JXM metrics in application.properties and expose the metrics endpoint

server.tomcat.mbeanregistry.enabled=true
management.endpoints.web.exposure.include=info,health,metrics

The go to http://localhost:8080/actuator/metrics/ and you will see all the available metrics.

For example current threads http://localhost:8080/actuator/metrics/tomcat.threads.current

Advertisement