AsynchronousFileChannel write operation, blocks sometimes?
<p>I recently started using Java AsynchronousFileChannel for a project of mine, where i want to write to files as quick as possible. When i came to test my project, i realised that maybe read and write operations where not really asynchronous for me! I made a very simple test program to see if write and read methods are blocking or not, by writing bytes to 2 files, one for each of my disks. </p>

<pre><code>ByteBuffer bufferc=ByteBuffer.allocate(75000000);//~75MB
ByteBuffer bufferd=ByteBuffer.allocate(75000000);
for (int i=0; i&lt;75000000; i++)
{   bufferc.put((byte)1);   bufferd.put((byte)1); }

bufferc.flip(); bufferd.flip();

ExecutorService executor = Executors.newFixedThreadPool(10);
AsynchronousFileChannel channelc =AsynchronousFileChannel.open(Paths.get("C:\\ppp"), getReadWriteOptions(),executor, new FileAttribute&lt;?&gt;[0]);
AsynchronousFileChannel channeld =AsynchronousFileChannel.open(Paths.get("D:\\ppp"), getReadWriteOptions(), executor, new FileAttribute&lt;?&gt;[0]);

long  start = System.currentTimeMillis();   
System.out.println("start");
Future futurec=channelc.write(bufferc, 0);
System.out.println(futurec.isDone());
Future futured=channeld.write(bufferd, 0);
System.out.println(futured.isDone());
long elapsedTimec = System.currentTimeMillis()- start; 

channelc.close();
channeld.close();
System.out.println("time="+elapsedTimec);
</code></pre>

<p>So, im writing two buffers, into two different files. Because each buffer is about 75 MB, i suppose that each buffer cannot be written immediatly to my disk, so i would expect as my output something  like</p>

<pre><code>false false time= 
</code></pre>

<p>which would mean for me that the write operations are "given" to the executorService, and the program continues to run. In multiple runs of this program, this does happen for me, but NOT always. I mean, i get output like</p>

<pre><code>start true true time=2621
</code></pre>

<p>or</p>

<pre><code>start false true time=3039
</code></pre>

<p>or if im lucky    </p>

<pre><code>start false false time=235
</code></pre>

<p>The times really differ, and i dont even understand why i do get the first two outputs! I'd like someone to explain me factors that affect this output, and/or how i am going to get only the 3rd of the above outputs!</p>
