I m 节目制作简便的Java NIO服务器,头痛很少: 页: 1 InputStreams i need to bens. 我只读了所有文字,这样就产生了一个问题:如果将暂停使用
我可以使用<条码>InputStream. Available()来检查是否有任何新数据,但如果我已经到达上游结束,那么我似乎知道:must打read(
)。
这为我创造了一个大的头痛,但我可能认为我是第一个提出这一问题的人。
我提出的唯一选择是:
- Have a separate thread for each
InputStream
, however that s just silly since I m using non-blocking I/O in the first place. I could also have a thread pool doing this but then again that limits the amount of simultaneous clients I can pipe theInputStream
to. - Have a separate thread reading these streams with a timeout (using another thread to interrupt if reading has lasted longer than a certain amount of time), but that ll most certainly choke the data flow should I have many open
InputStream
s not delivering data.
Of course, if there was a magic InputStream.isEof()
or isClosed()
then this wouldn t be any problem at all : (