try {
// do some stuffs that setup routes
} catch (Exception e) {
// log
Spark.stop();
}
The problem is that when an exception happens, the stop happens after what is run in the initialization thread happens and the app does not stop!
Usually the logs show the following:
2019-07-17T12:50:40,401Z INFO org.eclipse.jetty.util.log - Logging initialized @970ms to org.eclipse.jetty.util.log.Slf4jLog
2019-07-17T12:50:40,462Z ERROR c.b.a.s.p.backend.Backend - An error occurred during startup
java.lang.RuntimeException: java.lang.IllegalArgumentException
... etc ...
... 4 common frames omitted
2019-07-17T12:50:40,471Z INFO s.e.jetty.EmbeddedJettyServer - >>> Spark shutting down ...
2019-07-17T12:50:40,471Z INFO s.e.jetty.EmbeddedJettyServer - done
2019-07-17T12:50:40,503Z INFO s.e.jetty.EmbeddedJettyServer - == Spark has ignited ...
2019-07-17T12:50:40,503Z INFO s.e.jetty.EmbeddedJettyServer - >> Listening on 0.0.0.0:8081
2019-07-17T12:50:40,508Z INFO org.eclipse.jetty.server.Server - jetty-9.4.18.v20190429; built: 2019-04-29T20:42:08.989Z; git: e1bc35120a6617ee3df052294e433f3a25ce7097; jvm 11.0.3+7
2019-07-17T12:50:40,560Z INFO org.eclipse.jetty.server.session - DefaultSessionIdManager workerName=node0
2019-07-17T12:50:40,560Z INFO org.eclipse.jetty.server.session - No SessionScavenger set, using defaults
2019-07-17T12:50:40,562Z INFO org.eclipse.jetty.server.session - node0 Scavenging every 600000ms
2019-07-17T12:50:40,585Z INFO o.e.jetty.server.AbstractConnector - Started ServerConnector@62685b3d{HTTP/1.1,[http/1.1]}{0.0.0.0:8081}
2019-07-17T12:50:40,586Z INFO org.eclipse.jetty.server.Server - Started @1158ms
I have this kind of code :
The problem is that when an exception happens, the stop happens after what is run in the initialization thread happens and the app does not stop!
Usually the logs show the following: