public class ServerTest {
public static void main(String[] args) throws InterruptedException {
/**
* bossGroup, 父类的事件循环组只是负责连接,获取到连接后交给 workergroup的子事件循环组。
* 参数的获取,业务的处理等工作均是由workergroup这个子事件循环组来完成。
* 一个事件循环组一样可以完成所有的工作,但是Netty推荐的方式是使用两个事件循环组。
*/
EventLoopGroup bossGroup = new NioEventLoopGroup(); //创建父事件循环组
EventLoopGroup workerGroup = new NioEventLoopGroup(); //创建子类的事件循环组
try{
//创建启动服务器的对象
ServerBootstrap serverBootstrap = new ServerBootstrap();
/**
* group方法接收两个参数, 第一个为父事件循环组,第二个参数为子事件循环组
*/
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class) //bossGroup 的通道,只是负责连接
.childHandler(new TestChannelnitializer()); //设置子事件处理器,workerGroup的处理器,
ChannelFuture channelFuture = serverBootstrap.bind(8899).sync(); //绑定端口
channelFuture.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
当我们进行项目开发的时候,往往是需要应用程序的各组件、组件与后台线程间进行通信,
比如在子线程中进行请求数据,当数据请求完毕后通过Handler或者是广播通知UI,
而两个Fragment之家可以通过Listener进行通信等等。
当我们的项目越来越复杂,使用Intent、Handler、Broadcast进行模块间通信、
模块与后台线程进行通信时,代码量大,而且高度耦合。
现在就让我们来学习一下EventBus 3.0吧。
最近想学习使用spring5的使用!
sudo gitlab-ctl start # 启动所有 gitlab 组件;
sudo gitlab-ctl stop # 停止所有 gitlab 组件;
sudo gitlab-ctl restart # 重启所有 gitlab 组件;
sudo gitlab-ctl status # 查看服务状态;
sudo gitlab-ctl reconfigure # 启动服务;
sudo vim /etc/gitlab/gitlab.rb # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;
sudo gitlab-ctl tail # 查看日志;