@ -90,28 +90,34 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
synchronized ( this . monitor ) {
try {
addInstanceIdToEngineName ( ) ;
try {
// Remove service connectors to that protocol binding doesn't happen
// yet
removeServiceConnectors ( ) ;
// Remove service connectors to that protocol binding doesn't happen yet
removeServiceConnectors ( ) ;
// Start the server to trigger initialization listeners
this . tomcat . start ( ) ;
// Start the server to trigger initialization listeners
this . tomcat . start ( ) ;
// We can re-throw failure exception directly in the main thread
rethrowDeferredStartupExceptions ( ) ;
// We can re-throw failure exception directly in the main thread
rethrowDeferredStartupExceptions ( ) ;
Context context = findContext ( ) ;
try {
ContextBindings . bindClassLoader ( context , getNamingToken ( context ) ,
getClass ( ) . getClassLoader ( ) ) ;
}
catch ( NamingException ex ) {
// Naming is not enabled. Continue
}
Context context = findContext ( ) ;
try {
ContextBindings . bindClassLoader ( context , getNamingToken ( context ) ,
getClass ( ) . getClassLoader ( ) ) ;
// Unlike Jetty, all Tomcat threads are daemon threads. We create a
// blocking non-daemon to stop immediate shutdown
startDaemonAwaitThread ( ) ;
}
catch ( NamingException ex ) {
// Naming is not enabled. Continue
catch ( Exception ex ) {
containerCounter . decrementAndGet ( ) ;
throw ex ;
}
// Unlike Jetty, all Tomcat threads are daemon threads. We create a
// blocking non-daemon to stop immediate shutdown
startDaemonAwaitThread ( ) ;
}
catch ( Exception ex ) {
throw new EmbeddedServletContainerException (
@ -279,6 +285,7 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
@Override
public void stop ( ) throws EmbeddedServletContainerException {
synchronized ( this . monitor ) {
boolean wasStarted = this . started ;
try {
this . started = false ;
try {
@ -294,7 +301,9 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer
"Unable to stop embedded Tomcat" , ex ) ;
}
finally {
containerCounter . decrementAndGet ( ) ;
if ( wasStarted ) {
containerCounter . decrementAndGet ( ) ;
}
}
}
}