简体   繁体   中英

Check if embeded Tomcat was started

I am embedding Tomcat 7 into my Java application. In the constructor I set the variable:

this.tomcat = new Tomcat();
this.started = false;

I then have another method called at a later point to start it:

this.tomcat.start();
this.started = true;

I use the this.started variable to keep track of whether I ever started the server. Means that the state of the server is kept multiple times (internally by Tomcat and again in the variable). Ideally, I would like to just use the Tomcat API to get the status of the server, but I have not been able to find a method to do it.

The best alternative that I have found is trying to open a connection to the server. It seems like a slow (in CPU time scale) and resource inefficient solution.

this.tomcat.getServer().getState();

or

this.tomcat.getServer().getStateName();

Those are standard Lifecycle methods and can be called on the Server or any Engine, Host, Context, Connector, Realm etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM