This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit de7f52b53e57079a44701edc0932c4735c7d77c1 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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java b/java/org/apache/coyote/http2/Http2UpgradeHandler.java index fe60f32..2a2fee5 100644 --- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java +++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java @@ -30,6 +30,7 @@ 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; @@ -127,7 +128,7 @@ public class Http2UpgradeHandler extends AbstractStream implements InternalHttpU private long readTimeout = Http2Protocol.DEFAULT_READ_TIMEOUT; private long keepAliveTimeout = Http2Protocol.DEFAULT_KEEP_ALIVE_TIMEOUT; private long writeTimeout = Http2Protocol.DEFAULT_WRITE_TIMEOUT; - 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; @@ -1635,12 +1636,12 @@ public class Http2UpgradeHandler extends AbstractStream implements InternalHttpU 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