netty
原力与你同在
我,最后的绝地武士
展开
-
netty Slice 零拷贝 和 CompositeByteBuf
@Slf4jpublic class TestSlice { public static void main(String[] args) { ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(10); byteBuf.writeBytes(new byte[]{'a','b','c','d','e','f','g','h','i','j'}); byte[] bytes = new byte[10]原创 2022-02-16 11:13:34 · 359 阅读 · 0 评论 -
netty NioEventLoop
@Slf4jpublic class TestEventLoop { public static void main(String[] args) { NioEventLoopGroup group = new NioEventLoopGroup(2); // io 事件 普通任务 定时任务// DefaultEventLoopGroup eventExecutors = new DefaultEventLoopGroup(); // 普通任务 定时任务原创 2022-02-16 10:36:00 · 49 阅读 · 0 评论 -
netty closeFuture
@Slf4jpublic class CloseFutureClient3 { public static void main(String[] args) throws InterruptedException { // future和promise 的类型都是和异步方法配套使用,用来处理结果 NioEventLoopGroup group = new NioEventLoopGroup(); ChannelFuture channelFutur原创 2022-02-16 10:34:28 · 333 阅读 · 0 评论 -
netty ChannelFuture
@Slf4jpublic class HelloClient { public static void main(String[] args) throws InterruptedException { // future和promise 的类型都是和异步方法配套使用,用来处理结果 ChannelFuture channelFuture = new Bootstrap() .group(new NioEventLoopGroup())原创 2022-02-16 10:32:58 · 156 阅读 · 0 评论 -
netty Pipeline
@Slf4jpublic class TestPipeline { public static void main(String[] args) { new ServerBootstrap() .group(new NioEventLoopGroup()) .channel(NioServerSocketChannel.class) .childHandler(new ChannelIn原创 2022-02-16 10:31:15 · 1277 阅读 · 0 评论 -
netty Future和Promise
nettyFuture@Slf4jpublic class TestNettyFuture { public static void main(String[] args) throws ExecutionException, InterruptedException { // 当作线程池 NioEventLoop单个线程 NioEventLoopGroup group = new NioEventLoopGroup(); EventLoop e原创 2022-02-16 10:29:41 · 174 阅读 · 0 评论 -
nettyByteBuf
/** * 容量可以动态扩容 */public class TestByteBuf { public static void main(String[] args) { ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(); StringBuilder sb = new StringBuilder(); System.out.println(buf); for(int i=0;i<原创 2022-02-16 10:28:07 · 104 阅读 · 0 评论 -
netty服务器和客户端
服务器public class HelloServer { public static void main(String[] args) { // 1 启动器负责组装netty组件,启动服务器 new ServerBootstrap() // 2 group组 线程和选择器 .group(new NioEventLoopGroup()) // 选择实现 nio oio bi原创 2022-02-15 10:55:14 · 1253 阅读 · 0 评论 -
异步IO的简单理解
BIO NIO AIOAIO用来解决数据复制阶段的阻塞问题,异步IO不再作为重点io_uring原创 2022-02-11 14:31:08 · 684 阅读 · 0 评论 -
IO模型的5中模式
辨析阻塞IO非阻塞IO多路复用信号驱动异步IO参考:unix网络编程前言:在LInux系统下,用户空间会和内核空间可以互相切换阻塞IO阻塞IO:由用户空间切换成内核空间,内核空间在等待数据到达,数据到达后从网卡复制到内存,复制结束由内核空间切换成用户空间,读取。在此过程中用户线程一直被阻塞。(处理一个事件不能处理其他事件)同步阻塞非阻塞IO非阻塞IO:等待数据不阻塞,数据到达复制阶段也阻塞。同步非阻塞多路复用selector,先阻塞住,有事件过来才不阻塞;read也阻塞。节省了等等事件原创 2022-02-11 14:09:57 · 608 阅读 · 1 评论 -
nio服务多线程版本
public static void main(String[] args) throws IOException { Thread.currentThread().setName("boss"); ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); Selector boss = Selector.open();原创 2022-02-11 11:40:08 · 247 阅读 · 0 评论 -
netty学习
nio三大组件channelBuffercapacity 表示buffer能装的最大数据position 代表当前读写指针indexlimit 读写限制写模式:position写的位置;limit写的限制读模式:position度的位置;limit读的限制flip 切换读模式clear 切换写模式compact 压缩 读模式下,没有读完,需要写的时候调用selector...原创 2022-02-10 10:11:49 · 376 阅读 · 0 评论 -
nio编程service
public static void main(String[] args) throws IOException { // 创建select Selector selector = Selector.open(); ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); // 注册 select和channel联.原创 2022-02-10 18:04:11 · 300 阅读 · 0 评论 -
nio使用可写事件处理一次性写不完情况
服务端 public static void main(String[] args) throws IOException { ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); Selector selector = Selector.open(); ssc.register(selector, SelectionKey.O原创 2022-02-10 18:38:50 · 299 阅读 · 0 评论 -
nio文件和文件夹操作例子
统计一个文件夹下特定文件的数目public static void main(String[] args) throws IOException { // 统计文件夹出现的数目 AtomicInteger dirCount = new AtomicInteger(); // 统计文件出现的数目 AtomicInteger fileCount = new AtomicInteger(); Files.walkFileTree(Paths.原创 2022-02-10 14:12:14 · 269 阅读 · 0 评论