diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java index 33adf86279..3420d67bc8 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollEventLoop.java @@ -32,8 +32,6 @@ import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; import java.util.Queue; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; @@ -379,13 +377,9 @@ class EpollEventLoop extends SingleThreadEventLoop { } // Using the intermediate collection to prevent ConcurrentModificationException. // In the `close()` method, the channel is deleted from `channels` map. - Collection array = new ArrayList(channels.size()); + AbstractEpollChannel[] localChannels = channels.values().toArray(new AbstractEpollChannel[0]); - for (AbstractEpollChannel channel: channels.values()) { - array.add(channel); - } - - for (AbstractEpollChannel ch: array) { + for (AbstractEpollChannel ch : localChannels) { ch.unsafe().close(ch.unsafe().voidPromise()); } }