Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2013-03-04 22:28:32 +0000
committerRoberto E. Escobar2013-03-04 22:28:32 +0000
commit7a9169ce9a15dc892a8f603185d48b89cdf60c7a (patch)
tree5a36821cb31b7c9cfb0d347fb7c7f7c1dab62fc0 /plugins/org.eclipse.osee.executor.admin
parenta8b9f85df335f54ee722c6ced99a5f47b0f2a7bb (diff)
downloadorg.eclipse.osee-7a9169ce9a15dc892a8f603185d48b89cdf60c7a.tar.gz
org.eclipse.osee-7a9169ce9a15dc892a8f603185d48b89cdf60c7a.tar.xz
org.eclipse.osee-7a9169ce9a15dc892a8f603185d48b89cdf60c7a.zip
bug: Synchronize executor creation
Diffstat (limited to 'plugins/org.eclipse.osee.executor.admin')
-rw-r--r--plugins/org.eclipse.osee.executor.admin/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminImpl.java26
1 files changed, 10 insertions, 16 deletions
diff --git a/plugins/org.eclipse.osee.executor.admin/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminImpl.java b/plugins/org.eclipse.osee.executor.admin/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminImpl.java
index 8b3e944989..f811000eb0 100644
--- a/plugins/org.eclipse.osee.executor.admin/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminImpl.java
+++ b/plugins/org.eclipse.osee.executor.admin/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminImpl.java
@@ -36,7 +36,6 @@ public class ExecutorAdminImpl implements ExecutorAdmin {
private Log logger;
private EventService eventService;
private Timer timer;
- private boolean wasInitialized;
public void setLogger(Log logger) {
this.logger = logger;
@@ -62,11 +61,9 @@ public class ExecutorAdminImpl implements ExecutorAdmin {
timer.scheduleAtFixedRate(task, 0, THREAD_CHECK_TIME);
getEventService().postEvent(ExecutorConstants.EXECUTOR_ADMIN_REGISTRATION_EVENT, props);
- wasInitialized = true;
}
public void stop(Map<String, ?> props) {
- wasInitialized = false;
timer.cancel();
timer = null;
for (Entry<String, ExecutorService> entry : cache.getExecutors().entrySet()) {
@@ -76,23 +73,21 @@ public class ExecutorAdminImpl implements ExecutorAdmin {
getEventService().postEvent(ExecutorConstants.EXECUTOR_ADMIN_DEREGISTRATION_EVENT, props);
}
- private synchronized void ensureInitialized() throws Exception {
- if (!wasInitialized) {
- throw new IllegalStateException("Executor service was not properly initialized. Ensure start() is called.");
- }
- }
-
public ExecutorService getDefaultExecutor() throws Exception {
- ensureInitialized();
return getExecutor(DEFAULT_EXECUTOR);
}
public ExecutorService getExecutor(String id) throws Exception {
- ensureInitialized();
- ExecutorService service = cache.getById(id);
+ ExecutorService service = null;
+ synchronized (cache) {
+ service = cache.getById(id);
+ if (service == null) {
+ service = createExecutor(id);
+ cache.put(id, service);
+ }
+ }
if (service == null) {
- service = createExecutor(id);
- cache.put(id, service);
+ throw new IllegalStateException(String.format("Error creating executor [%s].", id));
}
if (service.isShutdown() || service.isTerminated()) {
throw new IllegalStateException(String.format("Error executor [%s] was previously shutdown.", id));
@@ -142,7 +137,7 @@ public class ExecutorAdminImpl implements ExecutorAdmin {
executor.shutdown();
boolean completed = false;
try {
- completed = executor.awaitTermination(10000, TimeUnit.SECONDS);
+ completed = executor.awaitTermination(5, TimeUnit.SECONDS);
} catch (Exception ex) {
// Do nothing;
}
@@ -161,7 +156,6 @@ public class ExecutorAdminImpl implements ExecutorAdmin {
@Override
public int cancelTasks(String id) throws Exception {
- ensureInitialized();
int itemsCancelled = 0;
ExecutorWorkCache workCache = cache.getWorkerCache(id);
if (workCache != null) {

Back to the top