fixed a few remaining executors to use only daemon threads so the VM can be shut down cleanly when needed

Change-Id: I1aaa83a01dba167df169ab0c28aa40d2c1617319
This commit is contained in:
Axel Uhl committed 2016-07-15 00:24:00 +02:00
1 parent 9a5b405ded
commit e4ba3e2832
9 files changed
+21 -9

No files matched your search

@@ -52,6 +52,7 @@ import com.sap.sailing.domain.tractracadapter.TracTracRaceTracker;
import com.sap.sse.common.Duration;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
import com.tractrac.model.lib.api.ModelLocator;
import com.tractrac.model.lib.api.event.CreateModelException;
import com.tractrac.model.lib.api.event.ICompetitor;
@@ -77,7 +78,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl
* A scheduler for the periodic checks of the paramURL documents for the advent of {@link IControl control points}
* with static position information otherwise not available through {@link MarkPassingReceiver}'s events.
*/
static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
/**
* This value indicated how many stored data packets we allow that are not in the right sequence Background: It can
@@ -11,7 +11,8 @@ Require-Bundle: com.sap.sailing.domain,
com.sap.sailing.declination,
com.sap.sailing.udpconnector,
com.sap.sailing.domain.common,
com.sap.sse.common
com.sap.sse.common,
com.sap.sse
Bundle-ActivationPolicy: lazy
Import-Package: org.osgi.framework
Bundle-Activator: com.sap.sailing.expeditionconnector.impl.Activator
@@ -8,6 +8,7 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import com.sap.sailing.domain.common.HttpMessageSenderServletConstants;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
/**
@@ -42,7 +43,7 @@ public class HttpServletMessageReceiver {
}
private static final Logger logger = Logger.getLogger(HttpServletMessageReceiver.class.getName());
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
private final Receiver receiver;
private long timestampOfLastHeartbeatReceived;
private final URL url;
@@ -486,6 +486,7 @@ import com.sap.sse.shared.media.impl.ImageDescriptorImpl;
import com.sap.sse.shared.media.impl.VideoDescriptorImpl;
import com.sap.sse.util.HttpUrlConnectionHelper;
import com.sap.sse.util.ServiceTrackerFactory;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
import com.sapsailing.xrr.structureimport.eventimport.RegattaJSON;
@@ -608,7 +609,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
executor = new ThreadPoolExecutor(/* corePoolSize */ THREAD_POOL_SIZE,
/* maximumPoolSize */ THREAD_POOL_SIZE,
/* keepAliveTime */ 60, TimeUnit.SECONDS,
/* workQueue */ new LinkedBlockingQueue<Runnable>());
/* workQueue */ new LinkedBlockingQueue<Runnable>(),
new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
}
/**
@@ -86,6 +86,7 @@ import com.sap.sse.common.Duration;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
public class SimulatorServiceImpl extends RemoteServiceServlet implements SimulatorService {
@@ -110,7 +111,8 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
Executor simulatorExecutor = new ThreadPoolExecutor(/* corePoolSize */THREAD_POOL_SIZE,
/* maximumPoolSize */THREAD_POOL_SIZE,
/* keepAliveTime */60, TimeUnit.SECONDS,
/* workQueue */new LinkedBlockingQueue<Runnable>());
/* workQueue */new LinkedBlockingQueue<Runnable>(),
new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
// TODO: initialize smart-future-cache for simulation-results and add to simulation-service
simulationService = SimulationServiceFactory.INSTANCE.getService(simulatorExecutor, null);
}
@@ -18,6 +18,7 @@ import com.sap.sailing.domain.common.trackfiles.TrackFilesFormat;
import com.sap.sailing.domain.trackimport.FormatNotSupportedException;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.server.trackfiles.TrackFileExporter;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
/**
* Export data to well-known formats such as GPX, KML etc. Internally, the RouteConverter Library is used.
@@ -55,7 +56,7 @@ public class TrackFileExporterImpl implements TrackFileExporter {
};
List<WriteRaceDataCallable> callables = new ArrayList<>();
ExecutorService executor = Executors.newCachedThreadPool();
ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
List<String> errors = new ArrayList<>();
for (TrackedRace race : races) {
for (TrackFilesDataSource d : data) {
@@ -59,6 +59,7 @@ import com.sap.sse.common.TimePoint;
import com.sap.sse.common.impl.MillisecondsDurationImpl;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.sap.sse.util.SmartFutureCache;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
public class SimulationServiceImpl implements SimulationService {
@@ -74,7 +75,7 @@ public class SimulationServiceImpl implements SimulationService {
public SimulationServiceImpl(Executor executor, RacingEventService racingEventService) {
this.executor = executor;
this.scheduler = Executors.newScheduledThreadPool(1);
this.scheduler = Executors.newScheduledThreadPool(1, new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
this.racingEventService = racingEventService;
if (racingEventService != null) {
this.raceListeners = new HashMap<String, SimulationRaceListener>();
@@ -7,3 +7,4 @@ Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: com.sap.sse.operationaltransformation
Require-Bundle: com.sap.sse
@@ -8,6 +8,8 @@ import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sap.sse.util.impl.ThreadFactoryWithPriority;
/**
* A very simple peer implementation for operational transformations that starts
@@ -64,7 +66,7 @@ public class PeerImpl<O extends Operation<S>, S> implements Peer<O, S> {
this.transformer = transformer;
currentState = initialState;
this.role = role;
this.merger = Executors.newSingleThreadExecutor();
this.merger = Executors.newSingleThreadExecutor(new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
}
public PeerImpl(String name, Transformer<S, O> transformer, S initialState, Role role) {
@@ -82,7 +84,7 @@ public class PeerImpl<O extends Operation<S>, S> implements Peer<O, S> {
S initialState = server.addPeer(this);
currentState = initialState;
this.role = Role.CLIENT;
this.merger = Executors.newSingleThreadExecutor();
this.merger = Executors.newSingleThreadExecutor(new ThreadFactoryWithPriority(Thread.NORM_PRIORITY, /* daemon */ true));
addPeer(server);
}