Hi Salmon Trout
The inaccurate delay (about 40%) is not caused by the sleep itself, but by the TASKLIST command being executed inside a loop (100 executions), concurrently with the Java program.
Sleeping a few milliseconds, instead of a second, will only increase this inaccuracy since more TASKLIST calls have to be made. In fact, sleeping 2 seconds 50 times results in a delay closer to 100 seconds. The drawback of this "sleep 2" solution is of course that each execution of the Java program will take at least 2 seconds.