netty的线程安全以及eventloop+channel关系

2019-10-11  本文已影响0人  monk87

netty中channel是线程安全的。因此,我们可以存储一个channel的引用,并且在需要向远端发送数据时,通过这个引用来调用channel相关的方法。即便此时有多个线程都在使用它,也不会出现多线程问题。而且,消息一定会按照顺序发送出去。

/**
 * Abstract base class for {@link OrderedEventExecutor}'s that execute all its submitted tasks in a single thread.
 *
 */
public abstract class SingleThreadEventExecutor extends AbstractScheduledEventExecutor implements OrderedEventExecutor {

    static final int DEFAULT_MAX_PENDING_EXECUTOR_TASKS = Math.max(16,
  //省略不相关代码
    private final Queue<Runnable> taskQueue;

    private volatile Thread thread;

上一篇 下一篇

猜你喜欢

热点阅读