l使用我自己的线程池来处理耗时的任务。我们知道One ChannelHanlder只能由一个EventLoop处理,一个eventloop可以处理一系列chanelhandler,所以它可以是线程安全的。但是当我使用自己的线程池时,net netty是否可以线程安全?如果netty可以,为什么?
ch.pipeline().addLast(bussLogicGroup, "ClientBussLogicGroup", clientHandler);
您可以从不与EventLoopGroup分开的其他非线程写入而不会导致任何问题。请参阅well-defined-thread-model尽管如此,用户仍然负责写入的顺序。来自链接的示例:
Channel ch = ...;
ByteBuf a, b, c = ...;
// From Thread 1 - Not the EventLoop thread
ch.write(a);
ch.write(b);
// .. some other stuff happens
// From EventLoop Thread
ch.write(c);
// The order a, b, and c will be written to the underlying transport is not well
// defined. If order is important, and this threading interaction occurs, it is
// the user's responsibility to enforce ordering.