code4fun

  • 主页

  • 归档

  • 标签

  • 分类

  • 关于

go mod与单元测试

发表于 2020-06-09 | 分类于 go
本文字数: 2.9k | 阅读时长 ≈ 3 分钟

使用go mod 解决go模块间的引用,和go的单元测试

阅读全文 »

python No module named xxx

发表于 2020-04-03
本文字数: 0 | 阅读时长 ≈ 1 分钟

RocketMQ的事务消息处理

发表于 2020-03-19 | 分类于 事务消息
本文字数: 377 | 阅读时长 ≈ 1 分钟

处理流程


阅读全文 »

RocketMQ的负载均衡源码分析

发表于 2020-03-18 | 更新于 2020-03-19 | 分类于 RocketMQ
本文字数: 6k | 阅读时长 ≈ 5 分钟

本文通过源码分析的方式对RocketMQ的负载均衡做一次简单的了解。

阅读全文 »

RocketMQ概念学习

发表于 2020-03-14 | 分类于 RocketMQ
本文字数: 3.2k | 阅读时长 ≈ 3 分钟

[toc]

架构图


阅读全文 »

Java NIO reactor模式介绍

发表于 2020-03-07 | 分类于 java
本文字数: 1.6k | 阅读时长 ≈ 1 分钟

[toc]

Reactor架构图

阅读全文 »

线程池的学习和使用

发表于 2020-03-06 | 分类于 java
本文字数: 5.3k | 阅读时长 ≈ 5 分钟

什么是线程池

线程池的作用是初始化一些线程,当有任务的时候,就从中启动一个来执行相关任务,执行完后,线程资源重新回收到线程池中,达到复用的效果,从而减少资源的开销;

本文将介绍线程池的创建方式、优化和实际使用这几个方面进行讲解;

阅读全文 »

基于netty的群聊

发表于 2020-03-03 | 分类于 netty
本文字数: 6.6k | 阅读时长 ≈ 6 分钟

基于netty的群聊

学了一段时间的netty知识,现在通过这个基于console的程序来对netty的相关接口做个简单的应用。

阅读全文 »

netty之NioEventLoopGroup源码解析

发表于 2020-02-28 | 分类于 netty,源码解析
本文字数: 1.7k | 阅读时长 ≈ 2 分钟

netty之NioEventLoopGroup源码解析

通过视频学习netty课程也有一段时间了,通过视频讲解的代码分析方式,自己也依葫芦画瓢尝试来一下子。

服务端代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public static void main(String[] args) {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();

try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new MyServerInitializor());

ChannelFuture channelFuture = serverBootstrap.bind(8899).sync();
channelFuture.channel().closeFuture().sync();

} catch (Exception e) {
e.printStackTrace();
}finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}

代码解读

在代码的2、3行种,声明了两个事件循环组(NioEventLoopGroup),一个bossGroup,一个workerGroup。它们的作用分别是:bossGroup 是服务端用了接收客户端连接的事件循环组,workergroup是用于处理客户端请求的事件循环组;

NioEventLoopGroup

类图

从类图的继承关系来看出,NioEventLoopGroup的顶层父类是Executor。由此可知,NioEventLoopGroup也是基于多线程来实现的。现在来看看它的具体实现。

####NioEventLoopGroup 的初始化过程

  1. 调用它的无参构造方法

    1
    2
    3
    4
    5
    6
    7
    8
     /**
    // 创建一个使用默认线程数的实例(通过默认的ThreadFactory创建)
    * Create a new instance using the default number of threads, the default {@link ThreadFactory} and
    * the {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
    */
    public NioEventLoopGroup() {
    this(0);
    }
    1
    2
    3
    4
    5
    6
    7
    /**
    * Create a new instance using the specified number of threads, {@link ThreadFactory} and the
    * {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
    */
    public NioEventLoopGroup(int nThreads) {
    this(nThreads, (Executor) null);
    }

未命名

发表于 2019-12-02
本文字数: 5.1k | 阅读时长 ≈ 5 分钟

Sentinel基于Apollo的持久化改造


title: Sentinel基于Apollo的持久化改造
date: 2019-12-02 14:41:03
categories: sentinel

tags: sentinel

Sentinel基于Apollo的持久化改造说明

阅读全文 »
12…4
Jian Nie

Jian Nie

34 日志
20 分类
31 标签
GitHub E-Mail
© 2020 Jian Nie | 129k | 1:57
|