This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit f258efef6c1e9c71ceaf1f50e1dc354f2514ab3a Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> AuthorDate: Mon Sep 28 14:53:25 2020 +0300 Optimize the iteration when closing idle streams --- java/org/apache/coyote/http2/Http2UpgradeHandler.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java b/java/org/apache/coyote/http2/Http2UpgradeHandler.java index 9f71af9..a1002c1 100644 --- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java +++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java @@ -29,7 +29,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -124,7 +124,7 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH private HpackDecoder hpackDecoder; private HpackEncoder hpackEncoder; - private final ConcurrentMap<Integer,AbstractNonZeroStream> streams = new ConcurrentSkipListMap<>(); + private final ConcurrentNavigableMap<Integer,AbstractNonZeroStream> streams = new ConcurrentSkipListMap<>(); protected final AtomicInteger activeRemoteStreamCount = new AtomicInteger(0); // Start at -1 so the 'add 2' logic in closeIdleStreams() works private volatile int maxActiveRemoteStreamId = -1; @@ -1530,12 +1530,12 @@ class Http2UpgradeHandler extends AbstractStream implements InternalHttpUpgradeH private void closeIdleStreams(int newMaxActiveRemoteStreamId) { - for (Entry<Integer,AbstractNonZeroStream> entry : streams.entrySet()) { - int id = entry.getKey().intValue(); - if (id > maxActiveRemoteStreamId && id < newMaxActiveRemoteStreamId) { - if (entry.getValue() instanceof Stream) { - ((Stream) entry.getValue()).closeIfIdle(); - } + final ConcurrentNavigableMap<Integer, AbstractNonZeroStream> subMap = streams.subMap( + Integer.valueOf(maxActiveRemoteStreamId), false, + Integer.valueOf(newMaxActiveRemoteStreamId), false); + for (AbstractNonZeroStream stream : subMap.values()) { + if (stream instanceof Stream) { + ((Stream)stream).closeIfIdle(); } } maxActiveRemoteStreamId = newMaxActiveRemoteStreamId; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org