This is about scattering and gathering byte channel api. As per the java doc and
theory-wise, Scattering and Gathering needs to be more efficient than individual
read/write of bytebuffers to a channel.
Please a take a look at the example attached here. The example opens a temp file
and writes an array of bytebuffers to the temp file. this writing is done in
two ways to comapre the time to write using array index in a loop and using
Gather api. Seems like gather is spending too much time in create direct buffer.
current output :
../../java-se-6/build/solaris-sparc/bin/java Gather 1000
transfer by Gather: time=28562 ms
transfer by Array time=150 ms
Expected outout:
Time consumed by Gather should be atleast less than or equal to that of Array.
Problem is reproducible on any JDK (5 or 6) and always.
Instructions to reproduce:
Supply the number of iterations (=~ number of bytebuffers in the array) as an arg.
I used 1000 for my testing. There is another bug that it will crash vm if there is no
memory (..expected to see a oom)