diff --git a/security-oauth2/src/main/java/io/micronaut/security/oauth2/client/clientcredentials/CacheableProcessor.java b/security-oauth2/src/main/java/io/micronaut/security/oauth2/client/clientcredentials/CacheableProcessor.java index 1ea38823e1..6948d6a855 100644 --- a/security-oauth2/src/main/java/io/micronaut/security/oauth2/client/clientcredentials/CacheableProcessor.java +++ b/security-oauth2/src/main/java/io/micronaut/security/oauth2/client/clientcredentials/CacheableProcessor.java @@ -23,8 +23,8 @@ import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; -import java.util.ArrayList; -import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Function; import java.util.stream.Collectors; @@ -50,7 +50,7 @@ class CacheableProcessor implements Processor { private Subscription subscription; @NonNull - private List> subscriptions = new ArrayList<>(); + private Queue> subscriptions = new ConcurrentLinkedQueue<>(); @Nullable private final Function transformer; @@ -83,7 +83,7 @@ public void clear() { } subscriptions = subscriptions.stream() .filter(elementSubscription -> !elementSubscription.isCanceled() && !elementSubscription.isComplete()) - .collect(Collectors.toList()); + .collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); } // Subscriber