Netty源码解析-NioEventLoop初始化

Netty 源码解析(六): Channel 的 register 操作 今天是猿灯塔“365篇原创计划”第六篇。 接下来的时间灯塔君持续更新Netty系列一共九篇 Netty 源码解析(一 ):开始 Netty 源码解析(二): Netty 的 Channel Netty 源码解析(三): Netty 的 Future 和 Promise Netty 源码解析(四): Netty 的 ChannelPipeline Netty 源码解析(五): Netty 的线程池... 阅读详情

    作为Netty的核心组件之一,NioEventLoop负责处理netty中的各种事件,每个NioEventLoop上有一个selector负责轮询IO事件,有一个定时任务队列及普通任务队列负责处理注册到NioEventLoop上的非IO任务。而1组NioEventLoop右由一个NioEventLoopGroup负责管理,默认一个NioEventLoopGroup管理2倍CPU核数的NioEventLoop。

    参照官网的服务端写法:
    

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workGroup = new NioEventLoopGroup();

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workGroup)
            .channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 128)
            .childOption(ChannelOption.SO_KEEPALIVE, true)
            .handler(new ChannelHandler())
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel socketChannel) throws Exception {
                    socketChannel.pipeline().addLast(new ChannelInboundA(), new ChannelInboundB(), new ChannelInboundC());
                }
            });

    try {
        ChannelFuture future = b.bind(port).sync();
        log.info("server start running");
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workGroup.shutdownGracefully();
    }
}

  1. NioEventLoop实在初始化NioEventLoopGroup的过程中被初始化;
  2. 当NioEventLoopGroup的构造参数不传值时,netty默认会为每个NioEventLoopGroup配置2倍的CPU核数个NioEventLoop:
    static {
            DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
                    "io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
    
            if (logger.isDebugEnabled()) {
                logger.debug("-Dio.netty.eventLoopThreads: {}", DEFAULT_EVENT_LOOP_THREADS);
            }
        }
  3. 最终调用到NioEventLoopGroup的父类MultithreadEventExecutorGroup的构造方法:
    protected MultithreadEventExecutorGroup(int nThreads, Executor executor,
                                            EventExecutorChooserFactory chooserFactory, Object... args) {
        if (nThreads <= 0) {
            throw new IllegalArgumentException(String.format("nThreads: %d (expected: > 0)", nThreads));
        }
    
        if (executor == null) {
            executor = new ThreadPerTaskExecutor(newDefaultThreadFactory());
        }
    
        children = new EventExecutor[nThreads];
    
        for (int i = 0; i < nThreads; i ++) {
            boolean success = false;
            try {
                children[i] = newChild(executor, args);
                success = true;
            } catch (Exception e) {
                // TODO: Think about if this is a good exception type
                throw new IllegalStateException("failed to create a child event loop", e);
            } finally {
                if (!success) {
                    for (int j = 0; j < i; j ++) {
                        children[j].shutdownGracefully();
                    }
    
                    for (int j = 0; j < i; j ++) {
                        EventExecutor e = children[j];
                        try {
                            while (!e.isTerminated()) {
                                e.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
                            }
                        } catch (InterruptedException interrupted) {
                            // Let the caller handle the interruption.
                            Thread.currentThread().interrupt();
                            break;
                        }
                    }
                }
            }
        }
    
        chooser = chooserFactory.newChooser(children);
    
        final FutureListener<Object> terminationListener = new FutureListener<Object>() {
            @Override
            public void operationComplete(Future<Object> future) throws Exception {
                if (terminatedChildren.incrementAndGet() == children.length) {
                    terminationFuture.setSuccess(null);
                }
            }
        };
    
        for (EventExecutor e: children) {
            e.terminationFuture().addListener(terminationListener);
        }
    
        Set<EventExecutor> childrenSet = new LinkedHashSet<EventExecutor>(children.length);
        Collections.addAll(childrenSet, children);
        readonlyChildren = Collections.unmodifiableSet(childrenSet);
    }
  4. 在该构造方法中主要做了3件事:
    1).创建一个线程执行器ThreadPerTaskExecutor,以便于后续NioEventLoop在处理task任务时,可直接调用io.netty.util.concurrent.ThreadPerTaskExecutor#execute该方法启动线程,异步执行任务。
    2).为NioEventLoopGroup创建EventExecutor数组,及NioEventLoop数组。
    3).为NioEventLoopGroup创建一个NioEventLoop旋转器,负责有事件事从NioEventLoop数组中选择NioEventLoop来执行任务。
  5. 创建ThreadPerTaskExecutor:
    1).
    executor = new ThreadPerTaskExecutor(newDefaultThreadFactory());
    2).调用newDefaultThreadFactory()设置NioEventLoop线程标识前缀:
    public DefaultThreadFactory(String poolName, boolean daemon, int priority, ThreadGroup threadGroup) {
        if (poolName == null) {
            throw new NullPointerException("poolName");
        }
        if (priority < Thread.MIN_PRIORITY || priority > Thread.MAX_PRIORITY) {
            throw new IllegalArgumentException(
                    "priority: " + priority + " (expected: Thread.MIN_PRIORITY <= priority <= Thread.MAX_PRIORITY)");
        }
    
        prefix = poolName + '-' + poolId.incrementAndGet() + '-';
        this.daemon = daemon;
        this.priority = priority;
        this.threadGroup = threadGroup;
    }
    其中poolName为nioEventLoopGroup,可以看到线程的前缀为nioEventLoopGroup-自增id-;
  6. NioEventLoopGroup轮询创建NioEventLoop线程组:
    1).调用NioEventLoopGroup的newChild方法:
    protected EventLoop newChild(Executor executor, Object... args) throws Exception {
        return new NioEventLoop(this, executor, (SelectorProvider) args[0],
            ((SelectStrategyFactory) args[1]).newSelectStrategy(), (RejectedExecutionHandler) args[2]);
    }
    2).进入NioEventLoop的构造:
    NioEventLoop(NioEventLoopGroup parent, Executor executor, SelectorProvider selectorProvider,
                 SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler) {
        super(parent, executor, false, DEFAULT_MAX_PENDING_TASKS, rejectedExecutionHandler);
        if (selectorProvider == null) {
            throw new NullPointerException("selectorProvider");
        }
        if (strategy == null) {
            throw new NullPointerException("selectStrategy");
        }
        provider = selectorProvider;
        selector = openSelector();
        selectStrategy = strategy;
    }
    a.首先调用父类构造保存线程执行器,创建taskQueue有界阻塞队列:
    protected SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor,
                                        boolean addTaskWakesUp, int maxPendingTasks,
                                        RejectedExecutionHandler rejectedHandler) {
        super(parent);
        this.addTaskWakesUp = addTaskWakesUp;
        this.maxPendingTasks = Math.max(16, maxPendingTasks);
        this.executor = ObjectUtil.checkNotNull(executor, "executor");
        taskQueue = newTaskQueue(this.maxPendingTasks);
        rejectedExecutionHandler = ObjectUtil.checkNotNull(rejectedHandler, "rejectedHandler");
    }
    b.父类构造执行结束后,再保存selectorProvider,和selectStrategy。
    c.为新创建的NioEventLoop创建一个selector:
    private Selector openSelector() {
        final Selector selector;
        try {
            selector = provider.openSelector();
        } catch (IOException e) {
            throw new ChannelException("failed to open a new selector", e);
        }
    
        if (DISABLE_KEYSET_OPTIMIZATION) {
            return selector;
        }
    
        final SelectedSelectionKeySet selectedKeySet = new SelectedSelectionKeySet();
    
        Object maybeSelectorImplClass = AccessController.doPrivileged(new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                try {
                    return Class.forName(
                            "sun.nio.ch.SelectorImpl",
                            false,
                            PlatformDependent.getSystemClassLoader());
                } catch (ClassNotFoundException e) {
                    return e;
                } catch (SecurityException e) {
                    return e;
                }
            }
        });
    
        if (!(maybeSelectorImplClass instanceof Class) ||
                // ensure the current selector implementation is what we can instrument.
                !((Class<?>) maybeSelectorImplClass).isAssignableFrom(selector.getClass())) {
            if (maybeSelectorImplClass instanceof Exception) {
                Exception e = (Exception) maybeSelectorImplClass;
                logger.trace("failed to instrument a special java.util.Set into: {}", selector, e);
            }
            return selector;
        }
    
        final Class<?> selectorImplClass = (Class<?>) maybeSelectorImplClass;
    
        Object maybeException = AccessController.doPrivileged(new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                try {
                    Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys");
                    Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys");
    
                    selectedKeysField.setAccessible(true);
                    publicSelectedKeysField.setAccessible(true);
    
                    selectedKeysField.set(selector, selectedKeySet);
                    publicSelectedKeysField.set(selector, selectedKeySet);
                    return null;
                } catch (NoSuchFieldException e) {
                    return e;
                } catch (IllegalAccessException e) {
                    return e;
                } catch (RuntimeException e) {
                    // JDK 9 can throw an inaccessible object exception here; since Netty compiles
                    // against JDK 7 and this exception was only added in JDK 9, we have to weakly
                    // check the type
                    if ("java.lang.reflect.InaccessibleObjectException".equals(e.getClass().getName())) {
                        return e;
                    } else {
                        throw e;
                    }
                }
            }
        });
    
        if (maybeException instanceof Exception) {
            selectedKeys = null;
            Exception e = (Exception) maybeException;
            logger.trace("failed to instrument a special java.util.Set into: {}", selector, e);
        } else {
            selectedKeys = selectedKeySet;
            logger.trace("instrumented a special java.util.Set into: {}", selector);
        }
    
        return selector;
    }
        再创建NioEventLoop的selector时,Netty除了调用JDK创建Selector外,还会将sun.nio.ch.SelectorImpl中保存SelectionKey的set集合利用反射用数组 SelectedSelectionKeySet替换掉该set集。
    Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys");
    Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys");
    
    selectedKeysField.setAccessible(true);
    publicSelectedKeysField.setAccessible(true);
    
    selectedKeysField.set(selector, selectedKeySet);
    publicSelectedKeysField.set(selector, selectedKeySet);
    SelectedSelectionKeySet添加SelectionKey时是直接在数组的最后有值位后添加,相比于set集合的add时间复杂度为O(1),SelectedSelectionKeySet的效率更高。
    @Override
    public boolean add(SelectionKey o) {
        if (o == null) {
            return false;
        }
    
        if (isA) {
            int size = keysASize;
            keysA[size ++] = o;
            keysASize = size;
            if (size == keysA.length) {
                doubleCapacityA();
            }
        } else {
            int size = keysBSize;
            keysB[size ++] = o;
            keysBSize = size;
            if (size == keysB.length) {
                doubleCapacityB();
            }
        }
    
        return true;
    }        
  7. 创建NioEventLoop旋转器:
    public EventExecutorChooser newChooser(EventExecutor[] executors) {
        if (isPowerOfTwo(executors.length)) {
            return new PowerOfTowEventExecutorChooser(executors);
        } else {
            return new GenericEventExecutorChooser(executors);
        }
    
    1).首选调用isPowerOfTwo(int val)判断NioEventLoopGroup的NioEventLoop线程组是否是2的幂:
    private static boolean isPowerOfTwo(int val) {
        return (val & -val) == val;
    }
    2).如果是2的幂执行PowerOfTowEventExecutorChooser的构造:
    private static final class PowerOfTowEventExecutorChooser implements EventExecutorChooser {
        private final AtomicInteger idx = new AtomicInteger();
        private final EventExecutor[] executors;
    
        PowerOfTowEventExecutorChooser(EventExecutor[] executors) {
            this.executors = executors;
        }
    
        @Override
        public EventExecutor next() {
            return executors[idx.getAndIncrement() & executors.length - 1];
        }
    }
            PowerOfTowEventExecutorChooser的构造保存NioEventLoop线程组,该类中还有一个next()方法,即是在有事件分配NioEventLoop时调用,下标是每次自增前&上线程数组的长度减1,利用机器码快速选择NioEventLoop;
    3).如果不是2的幂:
    private static final class GenericEventExecutorChooser implements EventExecutorChooser {
        private final AtomicInteger idx = new AtomicInteger();
        private final EventExecutor[] executors;
    
        GenericEventExecutorChooser(EventExecutor[] executors) {
            this.executors = executors;
        }
    
        @Override
        public EventExecutor next() {
            return executors[Math.abs(idx.getAndIncrement() % executors.length)];
        }
    }
            netty在不是2的幂时,分配NioEventLoop,调用next()获取NioEventLoop是自增前的值与线程组长度取余。
            显然与运算的效率要高于求余运算,可见Netty为了效率简直丧心病狂了。。。
  8. 整个NioEventLoop初始化流程就是这些了。Netty既是采用这种主从多线程模型实现高效的异步处理事件。服务端启动两个NioEventLoopGroup,一个boss,一个work,boss负责接受请求分发任务,work负责异步处理任务。boss和work下又有多个 NioEventLoop具体来做事。
Netty 4源码解析:服务端启动 Netty 4源码解析:服务端启动1.基础知识1.1 Netty 4示例因为Netty 5还处于测试版,所以选择了目前比较稳定的Netty 4作为学习对象。而且5.0的变化也不像4.0这么大,好多网上的例子都已经过时了。 <dependency> <groupId>io.netty</groupId> <artifactId>netty- 阅读详情

相关推荐

SRA数据下载的一个坑

SRA数据真坑啊!

xuzhougeng blog 3508

【Netty源码解析】NioEventLoop

上一篇博客【Netty源码学习】EventLoopGroup中我们介绍了EventLoopGroup,实际说来EventLoopGroup是EventLoop的一个集合,EventLoop是一个单线程的线程池,其接口和类实现关系如下:接下来我们主要介绍实现类NioEventLoop中实现的操作,通过NioEventLoop的继承关系图我们可以看到,其就是一个单线程的线程池。首先我们看NioEven

井底之蛙 2625

SOC设计必看!Tessent DRC检查中最容易踩的5个坑(附解决方案)

本文针对SOC设计中Tessent DRC检查的常见问题,详细分析了5个最易忽视的陷阱,包括时钟域交叉、扫描链虚连、多电压域规则等,并提供专业解决方案。特别针对芯片设计中的DFT验证难点,分享了经过验证的调试方法和Tessent工具使用技巧,帮助工程师提升DRC检查效率。

weixin_29280657的博客 496

NioEventLoop加载流程分析

一、我们首先看NioEventLoopGroup创建和初始化过程。 EventLoopGroup workEventLoopGroup = new NioEventLoopGroup(new NamedThreadFactory("clientThread", false)); 1.看下类继承图 2.MultithreadEventLoopGroup父类实现了channel的接口注册,next取下一个可用的NioEventLoop @Override public Event.

lipengyao2010的专栏 342

[QDS]从零开始,写第一个Qt Design Studio到程序调用的项目

最近在使用Qt Design Studio进行开发,但是简中网上要不就是只搜得到Qt Designer(Qt Creator内部库),要不就只搜得到一点营销号不知道从哪里搬来的账号,鉴于Qt Design Studio是一个这么强大的软件,自然是需要来进行一下小小的实践的。所以开了这篇文章,方便没有使用过Qt Design Studio 和 QML的开发者也可以快速上手QDS(Qt Design Studio)。在本文中,你将学会如何使用QDS开发一个简单的QML程序,与你的C++后端代码进行交流。

Andius的博客 8213

BUG调试案例一:RK3588+YT8531网络无法PING通调试案例

在使用 RK3588 搭配 YT8531S PHY 芯片进行网络调试时,遇到了“网络无法 Ping 通”的棘手问题。排查了两天,终于找到问题原因。为了避免大家在类似项目中走弯路,也为了加深自己对调试细节的理解,我们特意整理了本次问题的完整排查过程。本篇文章将围绕以下四个方面展开分享: 问题现象&描述 调试过程&分析 问题根源定位 注意事项提醒 举一反三(走两步)

案例文章,高速信号 2336

(三)Netty服务启动过程源码分析 — Selector的构建和优化

前言 继上一篇讲完了Channel的注册和初始化后,我们看看Netty的Selector是如何创建的,以及Netty是如何对他进行优化的 正文 io.netty.channel.nio.NioEventLoop // 在NioEventLoop初始化的时候,在构造方法里会调用openSelector()方法 private SelectorTuple openSelector() { final Selector unwrappedSelector;

OrPis的专栏 763

小白也能懂!一步步教你用FPGA加速YOLO目标检测(入门篇)

安装到 PYNQ 开发板中。该库为 PYNQ 平台提供了对量化神经网络(如 YOLO)的硬件加速支持。确保你的电脑已连接到外网,如 WiFi 或热点(手机热点理论上也可用,未实测)。当你看到安装成功的提示后,打开 Jupyter Notebook,你会发现在。趁这个机会,泡了杯茶,刷了会儿手机,顺便感慨了一下开源社区的强大……页面中多出了一些新的项目文件夹 —— 这就是我们刚才安装的。参数,浅拷贝只克隆最近一次提交,减少数据量,避免超时问题。初始化,打开该文件,即可运行我们的Tiny YOLO。

FJN110的博客 1597

Netty学习笔记通信调度篇:NioEventLoop源码解读

目录 初始化过程 Netty对Selecter的优化 注册channel过程 NioEventLoop的任务处理机制 run 方法实现 select 处理就绪事件 runAllTasks处理非I/O任务。 NioEventLoop 继承于 SingleThreadEventLoop, 而 SingleThreadEventLoop 又继承于 SingleThreadEventEx...

船长 645

《Zephyr OS 入门与实战》第15章:LoRaWAN 集成

【代码】《Zephyr OS 入门与实战》第15章:LoRaWAN 集成。

2301_79143213的博客 608

【DexGraspNet与多指手抓取算法详解】第四章 抓取检测网络架构设计

图 $G=(V, E)$ 包含两类节点:指尖节点 $V_{tip} = \{v_{tip}^i\}_{i=1}^{N_{finger}}$ 与物体表面节点 $V_{obj} = \{v_{obj}^j\}_{j=1}^{N_{surf}}$。节点特征包含位置 $x \in \mathbb{R}^3$ 、法向 $n \in \mathbb{R}^3$ 及视觉特征 $f \in \mathbb{R}^d$。

VectorShift的博客 440

Netty基础学习(二)

netty中的ByteBuffer,Channel,ChannelPipeline和ChannelHandler,ChannelFuture和Promise

西木风落 993

微信小程序 - 解决报错 operateAudio:fail audioInstance is not set(wx.getRecorderManager苹果ios真机调试运行,播放音频播放出错解决)

微信小程序,苹果ios系统,真机测试报错,播放音频报错operateAudio:fail audioInstance not exist,errCode: -1,小程序生成音频播放报错errMsg,真机调试报错开发者工具没问题,wx.getRecorderManager,音频实例,InnerAudioContext,各种方法都试了不行,只有ios苹果手机有这个问题,IOS 出现 operateAudio,在iOS无法播放的解决方案,更新到最新版本了还是不行,链接没有特殊字符,微信小程序全局音频设置,手机上播

🏆 前端领域优质创作者 1万+

Netty源码解析(三) —— NioEventLoop初始化

这节我们来分析NioEventLoop的代码实现,还记得上节在NioEventLoopGroup中我们创建NioEventLoop,下面先看它的继承关系 构造方法 /** * @param parent NioEventLoopGroup * @param executor 线程执行器 每次调用会创建一个name为nioEventLoopGroup-...

fanday的博客 891

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Netty4.0源码解析:NioEventLoop/NioEventLoopGroup的初始化

一、引言 Netty程序在启动时,需要指定最少一个EventLoopGroup实例(服务端引导可以指定2个,客户端引导只能指定1个)。一般情况下我们指定的EventLoopGroup实现类都是NioEventLoopGroup。在了解NioEventLoopGroup的作用及其内部实现原理之前,我们先来复习下Reactor线程模型: Reactor线程模型有三种类型:单线程模型、多线程模型和主从线...

APlus 1314

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

浅谈Netty中的NioEventLoop

NioEventLoop创建 步骤 new NioEventLoopGroup() 线程组,默认2*cpu new ThreadPerTaskExecutor() 线程创建器 每次执行任务都会创建一个线程实体 for(){newChild()} 构造NioEventLoop 保存线程执行器ThreadPerTaskExecutor 创建一个MpscQueue 创建一个selector ...

weixin_33862514的博客 231

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

netty : NioEventLoopGroup 源码分析

NioEventLoopGroup 源码分析 1. 在阅读源码时做了一定的注释,并且做了一些测试分析源码内的执行流程,由于博客篇幅有限。为了方便 IDE 查看、跟踪、调试 代码,所以在 github 上提供 netty 的源码、详细的注释及测试用例。欢迎大家 star、fork ! 2. 由于个人水平有限,对源码的分析理解可能存在偏差或不透彻的地方还请大家在评论区指出,谢谢! ...

昨夜凛雨 367

NioEventLoop解析

NioEventLoop解析

qq_40913932的博客 504

Netty源码分析系列之服务端Channel初始化

Netty中服务端的Channel是如何初始化的

天堂的博客 444

Netty源码剖析(NioEventLoopGroup创建流程)

原创不易,转载请注明出处 本文基于netty版本4.1.33.Final 文章目录前言1.Reactor网络模型简单介绍2.总结 前言 我们在《基于Netty实现一个服务端/客户端通信demo》一文中基于netty实现了一个nio服务端、客户端通信的demo,也算是初步玩了玩netty,体验了一下基于netty的nio网络编程,说实话我首次接触netty编程的时候很懵逼,而且在很长一段时间内都处于懵逼状态,根本记不住这些api,但是当我对java nio 编程很熟练,并且了解了netty核心运行原理的.

猿上生活 616

阅读 Netty 源码关于 NioEventLoop 和 Channel 初始化部分的思考

启动:Netty 很懒,你把任务扔进去它才启动线程。分配:一个线程(EventLoop)像是包工头,手下管着几千个工人(Channel)。每个工人只听这一个包工头的话。异步:包工头接活时,先给你开个收据(Future),然后让你一边玩去。活干完了,他再按收据上的电话通知你。队列:如果你想指挥工人干活,但你不是包工头,你不能直接吼工人。你得写个纸条(Task)塞进包工头的信箱(Queue)。包工头忙完手头的活(IO),会去信箱拿纸条执行。

Kiyra的博客 865

Netty源码解析一:客户端的连接源码分析

本篇博客不去具体分析Netty的使用,而是在能够使用netty的基础上去进一步分析其源码。 本文主要对客户端连接过程进行分析。 首先,在客户端建立起与服务器端连接的代码如下: public static void main(String[] args) { // 创建一个线程组 NioEventLoopGroup eventExecutors = new NioEventLoopGroup(); // 创建一个用来初始化的bs Bootstrap bootstrap = new B

qq_43739097的博客 312

NioEventLoopGroup 源码分析

NioEventLoopGroup 源码分析1. 在阅读源码时做了一定的注释,并且做了一些测试分析源码内的执行流程,由于博客篇幅有限。为了方便 IDE 查看、跟踪、调试 代码,所以在 github上提供 netty 的源码、详细的注释及测试用例。欢迎大家 star、fork !2. 由于个人水平有限,对源码的分析理解可能存在偏差或不透彻的地方还请大家在评论区指出,谢谢!从今天开始,就准备进军 ne...

James的博客 1011

Netty源码—1.服务端启动流程二

ServerBootstrap的bind()方法,首先执行AbstractBootstrap的initAndRegister()方法完成了服务端Channel的初始化和注册后,就会调用AbstractBootstrap的doBind0()方法绑定端口。AbstractUnsafe的bind()方法中所调用的doBind()方法是属于AbstractChannel的抽象接口,会由NioServerSocketChannel来进行具体的实现,即调用JDK底层NIO的bind()方法来绑定端口。

mjunz的博客 1219

第一章 Netty深入剖析之Netty服务端启动

最近一段时间在学习netty,但是不知道原理用起来总是觉得很懵逼,现在一系列的文章都是在大咖的讲解下结合我自己的理解总结出的一系列分析。汇总下来,有两个目的,一个目的是方便自己日后回顾快速复习,一是希望能对其他小伙伴产生帮助,如果是这样的话,也是级感欣慰,话不多说我们步入正题。 今天这一话的基本目录如下: 目录 服务端channel的创建 服务端channel 的初始化 channel注册到selector 服务端口的绑定 我们建立在一个基本服务端代码上做分析,代码如下: public .

c1523456的博客 1861

JavaEE 企业级分布式高级架构师(十九)异步事件驱动框架Netty(4)

Netty学习笔记Netty源码解析Client端启动Pipeline消息的传递与处理 Netty源码解析 Client端启动 Pipeline 消息的传递与处理

yangwei2048的博客 423
上一篇: AVL树旋转及代码实现
下一篇: Netty源码解析-ServerBootstrap及初始化服务端启动
ybin__
博客等级 码龄9年 1粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值