Browse Source

Use daemon threads with DefaultLoadBalancerCacheManager. (#890)

pull/904/head
Olga Maciaszek-Sharma 4 years ago committed by GitHub
parent
commit
3493612ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/cache/DefaultLoadBalancerCacheManager.java

13
spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/cache/DefaultLoadBalancerCacheManager.java vendored

@ -22,6 +22,8 @@ import java.util.Collections; @@ -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 @@ -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) {

Loading…
Cancel
Save