Skip to content

Commit

Permalink
Updates for Builds and Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
GedMarc committed Feb 24, 2024
1 parent b63046d commit 6e5a6fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/guicedee/guicedinjection/JobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public class JobService
private static TimeUnit defaultWaitUnit = TimeUnit.SECONDS;

private static final JobService INSTANCE = new JobService();
private static ExecutorService jobCleanup = null;

public static JobService getInstance(){
if (jobCleanup == null)
{
jobCleanup = INSTANCE.jobCleanup();
}
return INSTANCE;
}

Expand Down Expand Up @@ -223,6 +228,29 @@ public void waitForJob(String jobName, long timeout, TimeUnit unit)
service.close();
}

private ExecutorService jobCleanup()
{
ScheduledExecutorService jobsShutdownNotClosed = addPollingJob("JobsShutdownNotClosed", () -> {
for (String jobPool : getInstance().getJobPools())
{
ExecutorService executorService = serviceMap.get(jobPool);
if(executorService.isShutdown() && !executorService.isTerminated())
{
log.fine("Closing unfinished job - " + jobPool);
removeJob(jobPool);
}
if(executorService.isShutdown() && executorService.isTerminated())
{
log.fine("Cleaning terminated job - " + jobPool);
executorService.close();
serviceMap.remove(jobPool);
}
}
}, 2, TimeUnit.MINUTES);

return jobsShutdownNotClosed;
}

/**
* Adds a static run once job to the monitored collections
*
Expand Down

0 comments on commit 6e5a6fe

Please sign in to comment.