import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @Component public class TomcatMonitor { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired ServletWebServerApplicationContext applicationContext; @Scheduled(cron = "*/1 * * * * ?") public void execute() { TomcatWebServer webServer = (TomcatWebServer) applicationContext.getWebServer(); String tomcatInfo = webServer.getTomcat().getConnector().getProtocolHandler().getExecutor().toString(); System.out.println("tomcatInfo: " + tomcatInfo); } }
标签:SpringBoot,Tomcat,Component,TomcatWebServer,springframework,线程,tomcatInfo,org,im From: https://www.cnblogs.com/qianxiaoPro/p/16925313.html