Question

At my work we have a set up with the task scheduler periodically starting a java program to read mails. the task is scheduled to run every minute and it calls a .bat file which starts the java program.

Now the problem. Once in a month or so the jave.exe process doesn't end properly, so the next minute when it tries to run I get:

Task Scheduler failed to start "\XXX Jobs" task for user "NT AUTHORITY\System". Additional Data: Error Value: 2147750687.

And then I get that message every minute until I terminate the java.exe from the task manager.

Now my question, in task scheduler there are some options to choose. Under settings there is "If the task is already running, then the following rule applies" If I then choose "Stop the existing instance" Will this stop the java.exe or just the task? Or is there a better way.

Some advice would be welcome.

Was it helpful?

Solution 2

"Stop the existing instance" : The Task Scheduler service will stop the instance of the task that is already running, and run the new instance of the task.

that means it will kill the process that the scheduler has launched, cmd.exe in your case, as you told us your program is started from within a batch.

Now, i'm not familiar with java but i guess that stopping your batch will kill the java process that where launched if it is not started as a service.

The scheduler will then run another cmd process and execute your batch once again

OTHER TIPS

At the end of your batch file kill the task.

taskkill /im java.exe

java.exe could be whatever process you are planning on killing. You can add multiple lines of tasskill in a batch file to kill multiple processes at a time.

taskkill /im java.exe
taskkill /im explorer.exe
taskkill /im svhost.exe

Better solution would be fix the java hang. As the process starts every minute then in your java program should have the code to automatically exit if it takes more than a minute to complete the task. Another way would be in the batch file you can kill the process after 1 minute. Use the taskkill /im to kill the process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top