3

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.

4

1 回答 1

2

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.

于 2012-04-28T16:58:08.610 回答