I have an application that starts a thread by taking in some properties from the command prompt.I also have individual batch files to start the thread.
My problem is how to stop the thread already started as the requirement is another batch file which when invoked should stop the thread already started.
I am trying some options but the batch file starts a new jvm instance and I am not able to reference the thread already started from the other batch file.
Can anybody please help me on this ..
A couple of options:
1) Use your operating systems functions for managing processes to track down and kill the java process your program. This solution will be OS-specific.
2) Spawn an additional thread that monitors some network port (for example, using RMI) for a "shutdown" signal, and call System.exit() when this happens. This is trickier to manage, but it platform idependent.
A round about way but is still a standard way, is to create equivalent of .pid file. So similarly you could create a file that contains the thread info (searlized) when the thread starts. The next thread to start could read the file, if non empty, should kill the thread referenced by the content of the file, then it should overwrite the content of the file with that of the current threads content.
Hope it helps.