File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Stopping Server or System Shutdown Handeling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Stopping Server or System Shutdown Handeling " Watch "Stopping Server or System Shutdown Handeling " New topic

Stopping Server or System Shutdown Handeling

abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
My Project is a web based project with JSP and Servlet Technologies hosted by a JBoss Server.

In my application ,there is a option where user can call a exe run a separate application.
Is there any way in case the System is shut down or App Server is Restarted in that case a stop method should be invoked to
Stop the invoked process and clear certain Files from a location.

Thanks in advance.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Is the Process spawned off by a call to Runtime.exec()?
If yes,
1. store a handle to the Process object in your context scope. I
2. Implement the ServletContextListener interface which listens for lifecycle methods (start and shutdown of the web application).
3. In the contextDestroyed() method of the ServletContextListener, retrieve the process object and call destroy() on it.


Note : The runtime.exec() may not work well dependning on the platform and the kind of process you spawn. Read the javadoc to understand the limitations.
I agree. Here's the link:
subject: Stopping Server or System Shutdown Handeling
It's not a secret anymore!