Skip to content

Commit

Permalink
2.x: fix periodic scheduler purging config not honored (#5441)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Jun 27, 2017
1 parent 39e5d91 commit 31b41f8
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ private SchedulerPoolFactory() {
* Starts the purge thread if not already started.
*/
public static void start() {
if (!PURGE_ENABLED) {
return;
}
for (;;) {
ScheduledExecutorService curr = PURGE_THREAD.get();
if (curr != null && !curr.isShutdown()) {
Expand All @@ -78,7 +81,10 @@ public static void start() {
* Stops the purge thread.
*/
public static void shutdown() {
PURGE_THREAD.get().shutdownNow();
ScheduledExecutorService exec = PURGE_THREAD.get();
if (exec != null) {
exec.shutdownNow();
}
POOLS.clear();
}

Expand All @@ -90,10 +96,10 @@ public static void shutdown() {

if (properties.containsKey(PURGE_ENABLED_KEY)) {
purgeEnable = Boolean.getBoolean(PURGE_ENABLED_KEY);
}

if (purgeEnable && properties.containsKey(PURGE_PERIOD_SECONDS_KEY)) {
purgePeriod = Integer.getInteger(PURGE_PERIOD_SECONDS_KEY, purgePeriod);
}
if (purgeEnable && properties.containsKey(PURGE_PERIOD_SECONDS_KEY)) {
purgePeriod = Integer.getInteger(PURGE_PERIOD_SECONDS_KEY, purgePeriod);
}

PURGE_ENABLED = purgeEnable;
Expand All @@ -109,7 +115,7 @@ public static void shutdown() {
*/
public static ScheduledExecutorService create(ThreadFactory factory) {
final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1, factory);
if (exec instanceof ScheduledThreadPoolExecutor) {
if (PURGE_ENABLED && exec instanceof ScheduledThreadPoolExecutor) {
ScheduledThreadPoolExecutor e = (ScheduledThreadPoolExecutor) exec;
POOLS.put(e, exec);
}
Expand Down

0 comments on commit 31b41f8

Please sign in to comment.