Skip to content

Commit

Permalink
Only create FinalizerService executor if started
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Nov 7, 2018
1 parent 1fb288a commit d011454
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public class FinalizerService

private final Set<FinalizerReference> finalizers = Sets.newConcurrentHashSet();
private final ReferenceQueue<Object> finalizerQueue = new ReferenceQueue<>();
private final ExecutorService executor = newSingleThreadExecutor(daemonThreadsNamed("FinalizerService"));
@GuardedBy("this")
private ExecutorService executor;

@GuardedBy("this")
private Future<?> finalizerTask;
Expand All @@ -50,6 +51,9 @@ public synchronized void start()
if (finalizerTask != null) {
return;
}
if (executor == null) {
executor = newSingleThreadExecutor(daemonThreadsNamed("FinalizerService"));
}
if (executor.isShutdown()) {
throw new IllegalStateException("Finalizer service has been destroyed");
}
Expand All @@ -63,7 +67,10 @@ public synchronized void destroy()
finalizerTask.cancel(true);
finalizerTask = null;
}
executor.shutdownNow();
if (executor != null) {
executor.shutdownNow();
executor = null;
}
}

/**
Expand Down

0 comments on commit d011454

Please sign in to comment.