码迷,mamicode.com
首页 > 其他好文 > 详细

SimpleChannelInboundHandler和ChannelInboundHandlerAdapter区别

时间:2016-08-13 22:42:08      阅读:3195      评论:0      收藏:0      [点我收藏+]

标签:

一般用netty来发送和接收数据都会继承SimpleChannelInboundHandler和ChannelInboundHandlerAdapter这两个抽象类,那么这两个到底有什么区别呢?

其实用这两个抽象类是有讲究的,在客户端的业务Handler继承的是SimpleChannelInboundHandler,而在服务器端继承的是ChannelInboundHandlerAdapter。

最主要的区别就是SimpleChannelInboundHandler在接收到数据后会自动release掉数据占用的Bytebuffer资源(自动调用Bytebuffer.release())。而为何服务器端不能用呢,因为我们想让服务器把客户端请求的数据发送回去,而服务器端有可能在channelRead方法返回前还没有写完数据,因此不能让它自动release。

 

SimpleChannelInboundHandler和ChannelInboundHandlerAdapter区别

标签:

原文地址:http://www.cnblogs.com/Anders888/p/5769016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!