Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我们使用我们自己的线程池时,netty可以是线程安全的吗?如果内蒂可以,为什么?_Java_Multithreading_Netty - Fatal编程技术网

Java 当我们使用我们自己的线程池时,netty可以是线程安全的吗?如果内蒂可以,为什么?

Java 当我们使用我们自己的线程池时,netty可以是线程安全的吗?如果内蒂可以,为什么?,java,multithreading,netty,Java,Multithreading,Netty,l使用我自己的线程池来处理耗时的任务。我们知道一个ChannelHandler只能由一个EventLoop处理,一个EventLoop可以处理一系列ChanelHandler,因此它是线程安全的。但是当我使用我自己的线程池时,netty能保证线程安全吗?如果内蒂可以,为什么 ch.pipeline().addLast(bussLogicGroup, "ClientBussLogicGroup", clientHandler); 您可以从EventLoopGroup之外的其他非线程进行写入,而

l使用我自己的线程池来处理耗时的任务。我们知道一个ChannelHandler只能由一个EventLoop处理,一个EventLoop可以处理一系列ChanelHandler,因此它是线程安全的。但是当我使用我自己的线程池时,netty能保证线程安全吗?如果内蒂可以,为什么

 ch.pipeline().addLast(bussLogicGroup, "ClientBussLogicGroup", clientHandler);

您可以从EventLoopGroup之外的其他非线程进行写入,而不会导致任何问题。再见,不过用户T仍然负责写入的顺序。链接中的示例:

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.