Skip to content
Advertisement

Does an unhandled runtime exception crash the whole server?

Will an unhandled runtime exception stop the whole server (i.e. Spring Boot application) or just the specific HTTP request ?

It is true that an unhandled runtime exception will instantly shut down normal Java application, right ?

Advertisement

Answer

Will an unhandled runtime exception stop the whole server (i.e. Spring Boot application) or just the specific HTTP request ?

There is usually a thread pool in web server to handle all requests(e.g tomcat). Uncaught exceptions that occur in your controller will eventually be caught somewhere, so it will not cause the worker thread in the thread pool to be killed.

Tomcat#AbstractEndpoint#processSocket:

Executor executor = getExecutor();
if (dispatch && executor != null) {
    // handle request in thread poll
    executor.execute(sc);
} 

I did a simple debug. Assuming that an unhandle exception occurred in your controller, then the exception was actually caught by FrameworkServlet#processRequest. After the capture, it will be wrapped into a NestedServletException and continue to be thrown to the upper layer. Eventually, it will be caught and printed in StandardWrapperValve#invoke.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement