aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/Main.java7
-rw-r--r--src/org/traccar/WindowsService.java16
2 files changed, 22 insertions, 1 deletions
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index 73b18c139..48f2323ba 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -120,6 +120,13 @@ public final class Main {
}
}, 0, CLEAN_PERIOD);
+ Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(Thread t, Throwable e) {
+ LOGGER.error("Thread exception", e);
+ }
+ });
+
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
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;
}