ChannelGroup 在 Netty 4.1.6 中没有按预期工作

ChannelGroup not working as intended in Netty 4.1.6

我有一个 ChannelGroup 包含 4 个客户端,这些客户端已通过 Netty 方法 handlerAdded.handlerAdded.

逐个登录并添加到组中。
static ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); 

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    channels.add(ctx.channel());
    assignGroup(ctx.channel());
}

我稍后将我的 ChannelGroup 保存在一个名为 GameMaster 的对象中并初始化一个游戏循环,让每个客户端都有机会玩自己的回合:

    static ChannelGroup channels; // contains the actual channels, saved in contructor

    public void bettingPhase(boolean isOk) {
    int i = 0;
    int y = 0;

    for (Channel chan : channels) { // Should start on the first client that logged in
        Server.MyMessage.Builder message = Server.MyMessage.newBuilder();
        message.setKeyword("304");
        message.setValue("Please input a contract:");
        chan.writeAndFlush(message); // PROBLEM HERE
        while (isOk == false) { // Loop to check the playing client's input
            Server.MyMessage.Builder message2 = Server.MyMessage.newBuilder();
            try {
                Thread.sleep(1000);
                if (playerAnswer.getKeyword().equals("CONTRACT")) {
                    System.out.println("Player has inputed contract.");
                    i++;
                    message2.setKeyword("310");
                    chan.writeAndFlush(message); // Tells the current client his turn is over
                    System.out.println("End of turn for player.");
                    for (Channel channel : channels) { // Loop to tell the next client it's his turn
                        if (y == i) {
                            message2.setKeyword("309");
                            channel.writeAndFlush(message);
                            System.out.println("Start of turn for player.");
                        }
                        y++;
                    }
                    isOk = true;
                    playerAnswer.clearKeyword();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        isOk = false;
    }
}

请原谅这一大段代码。

但由于某种原因,我通过 chan.writeAndFlush(message); 发送的句子 "304 Please input a contract:" 被发送到另一个客户端(而不是第一个应该通过循环的客户端)!

我是不是漏掉了什么?

"first one"是什么意思? ChannelGroup 是一个 Set,它不保证迭代时保持插入顺序。