How to implement logic on stop and start of Java windows service wrapper YAJSW? -


i'm leatning work yajsw wrapping java apps windows services. works fine starting application want know how implement logic in java application when stop service perform logic inside java application.

something implementing onstart() , onstop() methods in java application can call these when start or stop java service.

you can call onstart() method/logic right inside main method entry point application. in order implement onstop(), how have done ...

step-1) create following class ...

public class shutdownhandler implements runnable {     public shutdownhandler() {         super();     }     @override     public void run() {         // call onstop() or code right here;     } } 

step-2) inside main method ...

thread shutdownthread = new thread(new shutdownhandler()); runtime.getruntime().addshutdownhook(shutdownthread); 

this invoke shutdownhandler's run method when java application terminates. hope helps.


Comments