poidasmith/winrun4j — pull request #66 by RedTailedHawk (2014-09-29 14:35:16+00:00)
Title: Added AbstractService.shutdownRequest() to allow subclasses to override ...

...and respond to a shutdown request on a thread other than main.

This allows my main thread to wait for a signal that the Windows service is shutting down, instead of polling and sleeping.

So instead of this:

while (!agentWindowsService.isShutdown()) {
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
}

This:

_blockingQueue = new ArrayBlockingQueue(1);

try {
_blockingQueue.take();
} catch (InterruptedException e) {
e.printStackTrace();
}

@Override
public void shutdownRequest() {
try {
_blockingQueue.put(true);
} catch (InterruptedException e) {
e.printStackTrace();
}