• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to programmatically stop an application mid-way in its start process

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to know how to stop an application programmatically mid-way, if a certain condition is raised. I do not want to code as System.exit(1) as it will terminate the entire JVM and more than 1 application running in the JVM will be shut down. My goal is to shut down only one application (among more than one) that is running in the same shared JVM. The application me be in the process of starting and if a certain condition is encountered, I want to stop the application from starting and shut down only that the application.

I was thinking that throwing a RuntimeException will stop the Spring based application from starting. But that is not true. The runtime exception was thrown, but that did not stop the application from starting.

Is there a way to stop the application from starting (and eventually stopping it), if a certain condition is raised?

Again, not coding as System.exit(1) that would trigger shutdownhook of the entire JVM.

Would like to find a solution for both stand-alone and web-based Java application.

I am using WebSphere 6.1 as application server.
 
author & internet detective
Posts: 41502
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WebSphere does stop the app if it fails to start in certain ways. For example, if a servlet throws an exception in init. Where in Spring are you executing code that you want it to stop? This may give a clue on what to do.
 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I am trying to do:

On application start-up, one of the Spring beans looks for a certain condition. If that condition is met, then do not want to start the application any more. Rather, terminate the application without shutting down the JVM (thus, not coding as System.exit(int)). On a side note, as because I cannot code System.exit(int), I cannot code for any shutdownhook either. This is because, shutdownhook gets executed only if the JVM is shutting down.

Now, the Spring bean (which looks for special condition to terminate application) is in a JAR project, which is a part of EAR project with web module. The goal was to localize special condition check only in the Spring bean that is a part of Jar project. For obvious reason, do not want to include Servlet related API in the Spring bean in the JAR project.In other words, the Spring bean in the JAR project shouuld have all the bells and whistles to terminate the application.

I understand that I can write custom code to dispose the intialized Spring beans when the special condition arises.

What I am unable to do is, stop the application from starting, when the special condition is reached. System.exit(int) is not an option.

What could I do to stop the application from starting when the special condition is met? I can write necessary code for clean-up. Is there a way to stop the application from starting?

Will the same code for stopping the application could be applicable for both stand-alone (JAR) and web based (EAR) application?

 
Jeanne Boyarsky
author & internet detective
Posts: 41502
881
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still learning Spring and don't know it well enough to answer your question. I'm going to move this to the Spring forum where someone is more likely to know.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic