hi i have changed a java process as the windows service. but in this whenever i am starting the windows service two java processes are running.it is spoiling my work totally can we have any way to remove a java process?

Recommended Answers

All 3 Replies

when the process starts, update a local kept file (bit like the system of a cookie) and set a value for key 'running' to true. right before terminating, set the value to false.

each time you start it, first make sure the current value is false, otherwise, don't start. this does may cause troubles if the applications terminates unexpectedly, though

Or how did you start the process? If you use windows scheduler, you should be able to set for only one process running. If you manually start or use a script to run (not windows scheduler), stultuske would be the way to go (even though you catch all exceptions, you still have problem if there is a blackout or user turns off the computer without closing your program).

With a file, sooner or later it's inevitable that the program will terminate abnormally in some way, leaving the file in the wrong state.
You could open a ServerSocket (a concurrent second attempt will throw a BindException), which has the advantage that the port should be released whenever the JVM terminates, or the user is logged off, or the computer restarts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.