Why is the need for Java NIOs -
Why is the need for Java NIOs -
i want know promising feature delivered part of java nios not nowadays in before normal ios. know next differences already:
java io | java nios stream oriented | buffer oriented blocking io | non blocking io selectors
java nios simplifies life in handling multiple read/write threads @ same time allow if had multiple cpus/huge cpu power, what's advantage of nios on normal ios. asked in 1 of interview , tried explaining using above points reply didn't seem satisfactory him.
the table below summarizes main differences between java nio , io. more detail each difference in sections next table. io stream oriented , blocking io ,nio buffer oriented , non blocking io
stream oriented vs. buffer oriented
the first big difference between java nio , io io stream oriented, nio buffer oriented. so, mean?
java io beingness stream oriented means read 1 or more bytes @ time, stream. read bytes you. not cached anywhere. furthermore, cannot move forth , in info in stream. if need move forth , in info read stream, need cache in buffer first.
java nio's buffer oriented approach different. info read buffer later processed. can move forth , in buffer need to. gives bit more flexibility during processing. however, need check if buffer contains info need in order process it. and, need create sure when reading more info buffer, not overwrite info in buffer have not yet processed. blocking vs. non-blocking io
java io's various streams blocking. means, when thread invokes read() or write(), thread blocked until there info read, or info written. thread can nil else in meantime.
java nio's non-blocking mode enables thread request reading info channel, , available, or nil @ all, if no info available. rather remain blocked until info becomes available reading, thread can go on else.
the same true non-blocking writing. thread can request info written channel, not wait written. thread can go on , else in mean time.
what threads spend idle time on when not blocked in io calls, performing io on other channels in meantime. is, single thread can manage multiple channels of input , output. selectors
java nio's selectors allow single thread monitor multiple channels of input. can register multiple channels selector, utilize single thread "select" channels have input available processing, or select channels ready writing. selector mechanism makes easy single thread manage multiple channels.
java nio
Comments
Post a Comment