tag:blogger.com,1999:blog-8712770457197348465.post858024163359155370..comments2024-03-29T03:17:04.645-07:00Comments on Javarevisited: Don't Call System.exit() on Java Web Application in Tomcat - Best Practicejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8712770457197348465.post-39574005022263815362021-01-20T18:51:10.526-08:002021-01-20T18:51:10.526-08:00Hello @Unknown, yes you can throw RuntimeException...Hello @Unknown, yes you can throw RuntimeException whenever expected conditions are not met but in web application, you don't really start anything. When you deploy your WAR file , servlet container like Tomcat configure URL path and initialize Servlet to process HTTP request. When Request comes, a Servlet or Filter is assigned based upon web.xml, the process is still the tomcat which can runjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-28873133488372173852021-01-19T20:44:48.449-08:002021-01-19T20:44:48.449-08:00So, instead of System.exit(1) or System.exit(0), w...So, instead of System.exit(1) or System.exit(0), we can use something like below <br /><br />throw new RuntimeException("error starting application"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90470531929839994132017-02-08T08:34:38.155-08:002017-02-08T08:34:38.155-08:00Fantastic explanation, thanks so much!Fantastic explanation, thanks so much!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-58399032002934767882016-08-27T18:03:21.338-07:002016-08-27T18:03:21.338-07:00Hello @rockey, if you just have your web applicati...Hello @rockey, if you just have your web application deployed in the server then you can stop the server, deploy new WAR file and restart the server. If it contains other application which cannot be stopped, then you need a webapp similar to manager webapp of tomcat. The stop and start the server is what many company use. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-74611033590340684432016-08-27T07:57:44.022-07:002016-08-27T07:57:44.022-07:00i have a web application running in production on ...i have a web application running in production on linux server so how can i stop that application and deploy my new jars ?what is the correct way rockeyhttps://www.blogger.com/profile/11958655585550461624noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22356699293610960102016-01-01T08:57:19.251-08:002016-01-01T08:57:19.251-08:00If the servlet container runs servlets under the d...If the servlet container runs servlets under the default security context on a mission critical server it deserves to be crashed. And sysadmin should be fired.Verhás Péterhttps://www.blogger.com/profile/06377161363854132582noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8847491336904737902014-12-09T23:09:38.649-08:002014-12-09T23:09:38.649-08:00Indeed, destroy() method is there for a reason and...Indeed, destroy() method is there for a reason and that is cleanup. This is also very important to prevent memory leak in Java application e.g. closing any database connection or releasing file handlers etc. In any case, you should not call System.exit() if you are running in a java server e.g. tomcat, glassfish, weblogic, websphere or jboss.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-26391419366383314892014-11-24T08:56:40.798-08:002014-11-24T08:56:40.798-08:00@Javin ..well still I can see and people ask lots ...@Javin ..well still I can see and people ask lots of questions in case of web application with respect to servlet specially..that..<br /><br />Is calling System.exit() inside a Servlet's destroy() method to forcefully kill any non-daemon threads a good idea?<br /><br />Calling System.exit() inside ANY servlet-related method is always 100% incorrect. Your code is not the only code running in SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.com