ITeye博客

关于mina的StreamIoHandler

wwty · 2010-06-19 22:12 · mina · 编程语言 · Apache · Mina · thread · Markdown

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

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)

暂无评论。

评论功能维护中,当前仅展示历史评论。