簡體   English   中英

當我們使用自己的線程池時,netty可以安全嗎? 如果可以,為什么?

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

我使用自己的線程池來處理耗時的任務。我們知道一個ChannelHanlder只能由一個EventLoop處理,而一個eventloop可以處理一系列chanelhandler,因此可以保證線程安全。 但是當我使用自己的線程池時,netty可以安全嗎? 如果可以,為什么?

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

您可以從不屬於EventLoopGroup的其他非線程中進行寫入,而不會引起任何問題。 請參閱定義良好的線程模型盡管用戶仍然負責寫入的順序。 來自鏈接的示例:

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM