欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

apache MINA 源码级分析-[贰]

程序员文章站 2022-06-05 23:18:47
...

http://rrsy23.iteye.com/blog/422689

http://rrsy23.iteye.com/blog/422589

 

需要先看前面的2篇 才能理解在说什么!

 

通过分离业务与io处理的线程池 这样 业务的阻塞不会导致IO处理的阻塞

 

[16:24:14] INFO [org.apache.mina.transport.socket.nio.NioSocketAcceptor] - accept an client connection thread info-->NioSocketAcceptor-1 [16:24:14] INFO [org.apache.mina.filter.logging.LoggingFilter] - OPENEDThread info--> NioProcessor-1 nextFilter is class org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1 [16:24:15] INFO [org.apache.mina.example.echoserver.EchoProtocolHandler] - OPENED Thread info--> pool-3-thread-1 [16:24:15] INFO [org.apache.mina.transport.socket.nio.NioSocketAcceptor] - accept an client connection thread info-->NioSocketAcceptor-1 [16:24:15] INFO [org.apache.mina.filter.logging.LoggingFilter] - OPENEDThread info--> NioProcessor-2 nextFilter is class org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1 [16:24:16] INFO [org.apache.mina.transport.socket.nio.NioSocketAcceptor] - accept an client connection thread info-->NioSocketAcceptor-1 [16:24:16] INFO [org.apache.mina.filter.logging.LoggingFilter] - OPENEDThread info--> NioProcessor-3 nextFilter is class org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1 [16:24:17] INFO [org.apache.mina.transport.socket.nio.NioSocketAcceptor] - accept an client connection thread info-->NioSocketAcceptor-1 [16:24:17] INFO [org.apache.mina.filter.logging.LoggingFilter] - OPENEDThread info--> NioProcessor-1 nextFilter is class org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1 [16:24:35] INFO [org.apache.mina.example.echoserver.EchoProtocolHandler] - --sleeping wake up 20 seconds---

 

从日志可以看出 现在 accept  ioprocess iohandler各自自己的线程池 这样才 真的异步

 

chain.addLast("threadPool", new ExecutorFilter(Executors.newSingleThreadExecutor()));

关键所在 不加则2,3车间公用一个线程池

实践不可能单线 一般

chain.addLast("threadPool", new ExecutorFilter(Executors.newCachedThreadPool()));

用什么线程池 自己实际考虑