@ -62,6 +62,8 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
private final boolean autoStart ;
private final boolean autoStart ;
private volatile boolean started ;
/ * *
/ * *
* Create a new { @link TomcatEmbeddedServletContainer } instance .
* Create a new { @link TomcatEmbeddedServletContainer } instance .
* @param tomcat the underlying Tomcat server
* @param tomcat the underlying Tomcat server
@ -174,6 +176,10 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
@Override
@Override
public void start ( ) throws EmbeddedServletContainerException {
public void start ( ) throws EmbeddedServletContainerException {
synchronized ( this . monitor ) {
if ( this . started ) {
return ;
}
try {
try {
addPreviouslyRemovedConnectors ( ) ;
addPreviouslyRemovedConnectors ( ) ;
Connector connector = this . tomcat . getConnector ( ) ;
Connector connector = this . tomcat . getConnector ( ) ;
@ -181,6 +187,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
startConnector ( connector ) ;
startConnector ( connector ) ;
}
}
checkThatConnectorsHaveStarted ( ) ;
checkThatConnectorsHaveStarted ( ) ;
this . started = true ;
TomcatEmbeddedServletContainer . logger
TomcatEmbeddedServletContainer . logger
. info ( "Tomcat started on port(s): " + getPortsDescription ( true ) ) ;
. info ( "Tomcat started on port(s): " + getPortsDescription ( true ) ) ;
}
}
@ -198,6 +205,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
getClass ( ) . getClassLoader ( ) ) ;
getClass ( ) . getClassLoader ( ) ) ;
}
}
}
}
}
private void checkThatConnectorsHaveStarted ( ) {
private void checkThatConnectorsHaveStarted ( ) {
for ( Connector connector : this . tomcat . getService ( ) . findConnectors ( ) ) {
for ( Connector connector : this . tomcat . getService ( ) . findConnectors ( ) ) {
@ -271,7 +279,11 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
@Override
@Override
public void stop ( ) throws EmbeddedServletContainerException {
public void stop ( ) throws EmbeddedServletContainerException {
synchronized ( this . monitor ) {
synchronized ( this . monitor ) {
if ( ! this . started ) {
return ;
}
try {
try {
this . started = false ;
try {
try {
stopTomcat ( ) ;
stopTomcat ( ) ;
this . tomcat . destroy ( ) ;
this . tomcat . destroy ( ) ;