Skip to content

Commit

Permalink
Another serialization related findbugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Dec 12, 2018
1 parent bde579e commit e4620d5
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,7 @@ public class AsyncResourceDisposer extends AdministrativeMonitor implements Seri
new NamingThreadFactory(new DaemonThreadFactory(), "AsyncResourceDisposer.worker")
);
// Can be static but instance field on a singleton does the job as well. Plus, it re-initializes between tests avoiding interference.
private transient final ExecutorService worker = new ContextResettingExecutorService(
new ThreadPoolExecutor(
0, MAXIMUM_POOL_SIZE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
THREAD_FACTORY,
// Ignore all WorkItems that does not fit into the pool to be rescheduled later
new ThreadPoolExecutor.DiscardPolicy()
)
);
private transient ExecutorService worker;

/**
* Persist all entries to dispose in order to survive restart.
Expand All @@ -115,6 +106,23 @@ public class AsyncResourceDisposer extends AdministrativeMonitor implements Seri
public AsyncResourceDisposer() {
super("AsyncResourceDisposer");
load();
readResolve();
}

private Object readResolve() {
if (worker == null) {
worker = new ContextResettingExecutorService(
new ThreadPoolExecutor(
0, MAXIMUM_POOL_SIZE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<>(),
THREAD_FACTORY,
// Ignore all WorkItems that does not fit into the pool to be rescheduled later
new ThreadPoolExecutor.DiscardPolicy()
)
);
}
return this;
}

/**
Expand Down

0 comments on commit e4620d5

Please sign in to comment.