Skip to content

Commit

Permalink
Version 2 Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Feb 4, 2024
1 parent 4a6a10d commit b63046d
Showing 1 changed file with 10 additions and 32 deletions.
42 changes: 10 additions & 32 deletions src/main/java/com/guicedee/guicedinjection/JobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,7 @@ public ExecutorService removeJob(String pool)
log.warning("Pool " + pool + " was not registered");
return null;
}

es.shutdown();
try
{
log.finer("Waiting for pool " + pool + " to shutdown cleanly.");
es.awaitTermination(defaultWaitTime, defaultWaitUnit);
} catch (Exception e)
{
log.log(Level.SEVERE, "Couldn't shut down pool" + pool + " cleanly in 60 seconds. Forcing.");
}
if (!es.isShutdown())
{
es.shutdownNow();
}
es.close();
waitForJob(pool);
serviceMap.remove(pool);
return es;
}
Expand All @@ -110,20 +96,7 @@ public ScheduledExecutorService removePollingJob(String pool)
log.warning("Repeating Pool " + pool + " was not registered");
return null;
}
es.shutdown();
try
{
log.finer("Waiting for repeating pool " + pool + " to shutdown cleanly.");
es.awaitTermination(defaultWaitTime, defaultWaitUnit);
} catch (Exception e)
{
log.log(Level.SEVERE, "Couldn't shut down pool" + pool + " cleanly in 60 seconds. Forcing.");
es.shutdownNow();
}
if (!es.isTerminated())
{
es.shutdownNow();
}
waitForJob(pool);
pollingMap.remove(pool);
return es;
}
Expand Down Expand Up @@ -205,7 +178,7 @@ public ExecutorService addJob(String jobPoolName, Runnable thread)
* @param jobPoolName
* @param thread
*/
public ExecutorService addJob(String jobPoolName, Callable<?> thread)
public Future<?> addTask(String jobPoolName, Callable<?> thread)
{
if (!serviceMap.containsKey(jobPoolName) || serviceMap.get(jobPoolName).isTerminated() || serviceMap.get(jobPoolName).isShutdown())
{
Expand All @@ -219,8 +192,7 @@ public ExecutorService addJob(String jobPoolName, Callable<?> thread)
removeJob(jobPoolName);
service = registerJobPool(jobPoolName, executorServiceSupplier.get());
}
service.submit(thread);
return service;
return service.submit(thread);
}

public void waitForJob(String jobName)
Expand All @@ -242,7 +214,13 @@ public void waitForJob(String jobName, long timeout, TimeUnit unit)
} catch (InterruptedException e)
{
log.log(Level.WARNING, "Thread didn't close cleanly, make sure running times are acceptable", e);
service.shutdownNow();
}
if (!service.isTerminated())
{
service.shutdownNow();
}
service.close();
}

/**
Expand Down

0 comments on commit b63046d

Please sign in to comment.