关于mina的StreamIoHandler

在网上看到这样一段讨论:

I was looking at the 2 HTTP examples in Mina1.1, and have always wondered
this:  Why, if at line 50 of
org.apache.mina.example.httpserver.stream.HttpProtocolHandler a comment says
"You *MUST* execute stream I/O logic in a separate thread." there is a
stream based HTTP server example?  Is this just for illustrative purposes
and not intended for production level systems?  Or does this comment not
hold true anymore?

问题说的是针对mina提供的一个http协议的例子说的,提供的例子中HttpProtocolHandler继承自StreamIoHandler。

 

As you know, InputStream.read() is a blocking operation.  If you block
the current I/O processor thread (or the thread pool thread) by
calling read(), it's simply a dead lock because the I/O processor (or
the event dispatcher) can't perform any I/O operation when you wait
for data.  That's why you need to spawn a new thread or use a
different thread pool.

回答的大致意思是说InputStream.read() 是一个阻塞的方法,为了应付阻塞,需要用线程来解决问题,所以建议不使用StreamIoHandler

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值