5

We are developing the web application using java. I want to use System.exit() in one of my methods instead of return. As per my knowledge, the application will go into shut down mode if I use this.

Could anybody give me suggestions on this?

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
User
  • 173
  • 1
  • 12

2 Answers2

5

In general, this is a pretty terrible idea, but the rule of thumb is System.exit() shuts down the entire JVM.

Your web application should be able to handle responses rather than just kill itself, I don't know of a good scenario where you'd ever want it to kill itself.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
David
  • 19,577
  • 28
  • 108
  • 128
  • Will it shutdown the JVM and the server also in which the application deplyos? – User Jan 29 '15 at 12:30
  • Yes, in as much as it'll shut down the container (Jboss / Tomcat / Glassfish) that also runs on the JVM. – David Jan 29 '15 at 12:49
  • If you are in development mode and you want to fail fast, `System.exit()` can be very helpful. Else you have to scroll back through log files to find out the root cause. Of course, you wouldn't use this in production mode. – Sridhar Sarnobat Jul 02 '18 at 23:05
5

System.exit() will shutdown the Servlet Container / (Tomcat) Similar question noted at When should we call System.exit in Java

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Paul John
  • 1,626
  • 1
  • 13
  • 15