diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-09-15 23:40:30 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-09-15 23:40:30 +1200 |
commit | 089e7262ab9395d0530c375b8f6cfcff35f45798 (patch) | |
tree | 28afcdd22f0fdc4d3b5d776851928db169ee5751 /src/org/traccar/WindowsService.java | |
parent | 22e360f7dd6ad6ee89896340123f85bd2537714a (diff) | |
download | trackermap-server-089e7262ab9395d0530c375b8f6cfcff35f45798.tar.gz trackermap-server-089e7262ab9395d0530c375b8f6cfcff35f45798.tar.bz2 trackermap-server-089e7262ab9395d0530c375b8f6cfcff35f45798.zip |
Improve service handling
Diffstat (limited to 'src/org/traccar/WindowsService.java')
-rw-r--r-- | src/org/traccar/WindowsService.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/org/traccar/WindowsService.java b/src/org/traccar/WindowsService.java index c1a5a1017..263d75a0e 100644 --- a/src/org/traccar/WindowsService.java +++ b/src/org/traccar/WindowsService.java @@ -36,6 +36,8 @@ public abstract class WindowsService { private static final Advapi32 ADVAPI_32 = Advapi32.INSTANCE; + private final Object waitObject = new Object(); + private String serviceName; private ServiceMain serviceMain; private ServiceControl serviceControl; @@ -186,12 +188,21 @@ public abstract class WindowsService { run(); + try { + synchronized (waitObject) { + waitObject.wait(); + } + } catch (InterruptedException ex) { + } + reportStatus(Winsvc.SERVICE_STOPPED, WinError.NO_ERROR, 0); // Avoid returning from ServiceMain, which will cause a crash // See http://support.microsoft.com/kb/201349, which recommends // having init() wait for this thread. // Waiting on this thread in init() won't fix the crash, though. + + System.exit(0); } } @@ -203,7 +214,10 @@ public abstract class WindowsService { case Winsvc.SERVICE_CONTROL_STOP: case Winsvc.SERVICE_CONTROL_SHUTDOWN: reportStatus(Winsvc.SERVICE_STOP_PENDING, WinError.NO_ERROR, 5000); - System.exit(0); + synchronized (waitObject) { + waitObject.notifyAll(); + } + break; default: break; } |