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- 阅读详情

相关推荐

无人机芯片模块技术要点分析

恶劣环境下信号稳定性:无人机在恶劣环境下工作时,遥感系统采集的信号往往很不稳定,视频信号处理芯片需要具备强抗干扰能力,能辨别脉冲脉宽为50ns以上、幅度为0V~4.5V的输入信号。这种架构能兼顾强大的运算能力和灵活的接口控制。芯片小型化:麻省理工学院的研究人员已设计出仅20平方毫米的微型芯片,可处理无人机飞行所需的惯性数据和相机图像,为微型无人机的发展奠定了基础。光子集成芯片(PIC) :研究显示,与电子芯片相比,光子计算芯片在延迟、计算容量和能效上都有数量级的提升,有望解决当前无人机系统的计算瓶颈。

YUNZHUO666的博客 1404

【Netty源码解析】NioEventLoop

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

井底之蛙 2625

Proteus仿真——电压比较器

电压比较器是一种对输入信号进行鉴别与比较的电路,是组成非正弦波发生电路的基本单元电路。常用电压比较器有如下几种:单限比较器、滞回比较器、窗口比较器、集成电压比较器等。

weixin_58745307的博客 3376

NioEventLoop加载流程分析

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

lipengyao2010的专栏 342

车窗标定工作流程

标定简单来说就是修改防夹参数来适配对应的车型,所有的防夹的参数在vers_userdef.h文件中定义。#标定内容。

qq_21274991的博客 4271

用 SAP ABAP ALV 重塑 SM30:可扩展的自定义表维护视图与自动传输实践

文章摘要: 本文提出了一种基于ALV Grid的动态表维护框架,用于替代传统SM30维护视图。该方案通过输入表名自动生成维护界面,支持动态筛选、批量操作和自动传输管理。核心设计包括:利用BAdI实现扩展点、通过行状态字段简化数据变更跟踪、使用Style Table控制单元格编辑权限、集成CTS实现自动传输。相比SM30标准维护,该框架显著提升了交互体验(支持ALV排序/过滤/汇总)和业务扩展性(统一校验与权限控制),同时解决了"维护+传输"流程割裂的问题。文中详细阐述了技术实现方案,并提

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 318

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

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

OrPis的专栏 763

Educoder:爬虫实战——求是网周刊文章爬取

第1关:获取新闻url importrequests importre defgeturls(): #**********Begin**********# url='http://www.qstheory.cn/dukan/qs/2014/2019-01/01/c_1123924172.htm' headers={ 'User-Agent':'Mozilla/5.0(Linux;Android6.0;Nexus5Buil...

weixin_46026136的博客 5254

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

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

船长 645

BevFusion (1): 传感器介绍

激光雷达,也称光学雷达(LIght Detection And Ranging)是激光探测与测距系统的简称,它通过测定传感器发射器与目标物体之间的传播距离,分析目标物体表面的反射能量大小、反射波谱的幅度、频率和相位等信息,从而呈现出目标物精确的三维结构信息。激光雷达是自动驾驶车辆的关键传感器,如下图所示,车辆上方旋转的圆柱体对应就是激光雷达传感器。

@bangbang的博客 1475

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

http://www.cierobot.com 4095

Netty基础学习(二)

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

西木风落 993

【论文精读】Graph WaveNet-深度时空图模型

Graph WaveNet构建了一个自适应邻接矩阵,它能保留隐藏的空间依赖关系,能够自动从数据中发现未见的图结构。提出了一个有效且高效的框架,可同时捕捉空间和时间依赖关系。其核心思想是将其提出的图卷积与扩张因果卷积相结合,使每个图卷积层都能处理空间依赖关系。在交通数据集上评估了提出的模型,并以较低的计算成本获得了最先进的结果。

打酱油的葫芦娃 1007

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

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

fanday的博客 891

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

VB摄像头监控

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

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

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

APlus 1314

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

浅谈Netty中的NioEventLoop

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

weixin_33862514的博客 231

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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、付费专栏及课程。

余额充值