Path: csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: NIO not so hot Date: Mon, 26 May 2014 23:50:15 +0200 Lines: 36 Message-ID: References: <81u5o9pfr44rtq9loivhrpe178lcql92r5@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Dh67g+L+ED2mHCZPsNfMJQIsZxneET69jpI/mbDPbE974jGzQ= Cancel-Lock: sha1:oBflPK/Clo29L3NO8lFs+RIZ2rc= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: <81u5o9pfr44rtq9loivhrpe178lcql92r5@4ax.com> Xref: csiph.com comp.lang.java.programmer:28568 On 26.05.2014 10:24, Roedy Green wrote: > On Sun, 18 May 2014 13:38:30 +0200, Robert Klemme > wrote, quoted or indirectly quoted > someone who said : > >> However, the test is quite unrealistic since this is not how NIO is >> usually used. > > With this particular benchmark I was not trying to demonstrate the use > of NIO, but decide the optimal way to read a whole file of characters > at a time, something I do very often. Why do you do that? Wouldn't that run the risk of using too much memory? I mean, usually you want to extract information from the file > I just have vague notion that if you keep your data in buffers, off > the Java heap, and ignore most of it, NIO will work faster than > ordinary I/O. You do not necessarily have to ignore it. But as long as you just do raw IO (i.e. copying data from one place to the other) then direct ByteBuffer seems to perform best. > I would be happy to post some sample code, explanations etc. at > http://mindprod.com/jgloss/nio.html > if you are up to expounding on NIO. Others have more time and experience to do that. NIO is more complicated and offers more control for a greater variety of use cases. If you just want to serially read a file using blocking IO the old IO is probably best - even performance wise, as we have seen. Kind regards robert