2013年12月1日星期日

New io how to implement asynchronous ?


FileChannel fc =  new FileOutputStream().getChannel();
fc.read( buff);

The above two lines of code , if there are multiple FileChannel to read , how to achieve asynchronous read ? If FileChannel not achieve asynchronous , it is better to use the old io Well, just more than a thread-safe .
socket stream can be asynchronous , other streams InputStream how to implement asynchronous ?
------ Solution ---------------------------------------- ----
file stream asynchronous read , in addition to their own trouble, does not seem ( under normal circumstances ) what the real meaning.
------ For reference only -------------------------------------- -

file stream without an asynchronous read is not a problem. I mean, what use FileChannel.
Then nonblocking socket stream in the end just be able to traverse , or every time the channel is asynchronous read and write .
------ For reference only -------------------------------------- -
answer is not asynchronous , asynchronous only asy ... channel
------ For reference only ---------------------- -----------------

local file , then it is.

没有评论:

发表评论