0

我有一个正在开发的 websocket 应用程序。这是 Netty 处理程序的代码。

在其中,websockets 连接到一个长时间运行的线程,该线程收集它们并传回消息。

我的问题涉及同步。因此,当 Netty 应用程序向线程添加新的 ctx 时,我使用锁来同步列表的添加/删除/迭代。我认为没有其他方法可以解决此锁定问题。

所以我的问题是有没有更好的方法来处理这种与线程的同步?

此外,执行此锁定是否有任何主要的性能缺陷?这会导致什么样的问题?

4

1 回答 1

1

I think what you want to use is the DefaultChannelGroup[1] for group channels and write to all of them. Another cool thing about it is that the Channel will get removed automatically once it close.

[1] http://netty.io/4.0/api/io/netty/channel/group/DefaultChannelGroup.html

于 2013-03-26T05:32:24.110 回答