study link: http://netty.io/3.6/guide/#architecture程序員
應用場景:web
Chat server that requires persistent connections and server push technology (e.g. Comet)socket
Media streaming server that needs to keep the connection open until the whole media is streamed (e.g. 2 hours of video)async
File server that allows the uploading of large files without memory pressure (e.g. uploading 1GB per request)ide
Scalable mash-up client that connects to tens of thousands of 3rd party web services asynchronouslyui
高級特性:線程
1. Codec (means encode and decode - usually you need to codec the requests from socket stream)netty
2. SSL (secure socket layer) / TLS (transport layer security) supportcode
3. HTTP easy implementationcomponent
4. webSocket support
5. Google Protocol Buffer Integration - binary protocol ?!
powerful architecture. It is composed of three components - buffer, channel, and event model- and all advanced features are built on top of the three core components
Guide:
Request will be read by Channel into ChannelBuffer
Meanwhile it will publish the ChannelEvent to the ChannelHandlers in the ChannelPipeline
ChannelEvent.getChannel()
Response will be generated by ChannelHandlers into ChannelBuffer, lastly write into Channel back to client
* new NioServerSocketChannelFactory( Executors.newCachedThreadPool()
無界線程池,能夠進行自動線程回收。
在JDK幫助文檔中,有如此一段話: 「強烈建議程序員使用較爲方便的 Executors 工廠方法 Executors.newCachedThreadPool()(無界線程池,能夠進行自動線程回收)、Executors.newFixedThreadPool(int)(固定大小線程池)和 Executors.newSingleThreadExecutor()(單個後臺線程),它們均爲大多數使用場景預約義了設置。」
More details about ThreadPool tech, you can check http://dongxuan.iteye.com/blog/901689
newFixedThreadPool newSingleThreadExecutor newCachedThreadPool