简体   繁体   中英

When we use our own thread pool, Can netty be thread safe? if netty can, Why?

l use my own thread pool to process the time consuming task.we know One ChannelHanlder can only be processed by one EventLoop and one eventloop can process a chain of chanelhandlers,so it can be thread safe. but when l use my own thread pool, Can netty be thread safe? if netty can, Why?

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

You are able to write from other non threads not apart of the EventLoopGroup without causing any problems. See well-defined-thread-model You the usert are still responsible for the ordering of the writes though. Sample from the link:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM