package cn.bunny.demo2;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.NettyRuntime;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class TestGroupLoop {
    public static void main(String[] args) {
        // io 事件普通任务、定时任务
        NioEventLoopGroup group = new NioEventLoopGroup();
        // 获取下一个事件循环对象
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());
        // 执行普通任务
        group.next().submit(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("执行完成");
        });

        // 执行定时任务
        group.next().scheduleAtFixedRate(() -> {
            log.debug("定时任务的执行");
        }, 0, 1, TimeUnit.SECONDS);
    }

    private static void test1() {
        // io 事件普通任务，定时任务
        NioEventLoopGroup group = new NioEventLoopGroup();
        // 普通任务，定时任务
        DefaultEventLoopGroup eventLoopGroup = new DefaultEventLoopGroup();
        // 查看系统是几核
        System.out.println(NettyRuntime.availableProcessors());
    }
}
