Skip to content

Commit

Permalink
Fix threading issue with ThreadedLRUCacheStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
kpartlow committed Feb 23, 2025
1 parent 75e88a1 commit 2c303c4
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ public class ThreadedLRUCacheStrategy<K, V> implements Map<K, V> {
private final AtomicBoolean cleanupScheduled = new AtomicBoolean(false);

// Shared ScheduledExecutorService for all cache instances
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
// set thread to daemon so application can shut down properly.
private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
Thread thread = new Thread(r, "LRUCache-Purge-Thread");
thread.setDaemon(true);
return thread;
});

/**
* Inner class representing a cache node with a key, value, and timestamp for LRU tracking.
Expand Down Expand Up @@ -298,4 +303,4 @@ public static void shutdown() {
Thread.currentThread().interrupt();
}
}
}
}

0 comments on commit 2c303c4

Please sign in to comment.