Use daemon threads with DefaultLoadBalancerCacheManager. (#890)
This commit is contained in:
committed by
GitHub
parent
65201f8f61
commit
3493612ab4
@@ -22,6 +22,8 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.stoyanr.evictor.map.ConcurrentHashMapWithTimedEviction;
|
||||
@@ -68,11 +70,20 @@ public class DefaultLoadBalancerCacheManager implements LoadBalancerCacheManager
|
||||
.map(name -> new DefaultLoadBalancerCache(name,
|
||||
new ConcurrentHashMapWithTimedEviction<>(
|
||||
loadBalancerCacheProperties.getCapacity(),
|
||||
new DelayedTaskEvictionScheduler<>()),
|
||||
new DelayedTaskEvictionScheduler<>(
|
||||
aScheduledDaemonThreadExecutor())),
|
||||
loadBalancerCacheProperties.getTtl().toMillis(), false))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private ScheduledExecutorService aScheduledDaemonThreadExecutor() {
|
||||
return Executors.newSingleThreadScheduledExecutor(runnable -> {
|
||||
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Cache getCache(String name) {
|
||||
|
||||
Reference in New Issue
Block a user