views:

212

answers:

1

This question spans both serverfault and stackoverflow so I just picked this one.

I get the following exception with some simple file copy code. Its running on Windows Server 2003 x64

Caused by: java.io.IOException: Insufficient system resources exist to complete the requested service
at sun.nio.ch.FileDispatcher.pwrite0(Native Method)
at sun.nio.ch.FileDispatcher.pwrite(Unknown Source)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.FileChannelImpl.write(Unknown Source)
at sun.nio.ch.FileChannelImpl.transferFromFileChannel(Unknown Source)
at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
at Tools.copy(Tools.java:473)

public static void copy(FileChannel input, FileChannel output) throws IOException {
    final long size = input.size();
    long pos = 0;
    while (pos < size) {
        final long count = (size - pos) > FIFTY_MB ? FIFTY_MB : (size - pos);
        pos += output.transferFrom(input, pos, count);
    }
}

The thing is the server that is running this code is brand new and super powerful, so I don't understand what system resource it could possibly be running out of.

This looks like the error described here: http://support.microsoft.com/kb/304101

But I've tried adding the registry edits to increase kernel memory page size, and that didn't help.

What I really don't get is I've seen code that uses FileChannel transferFrom with a lot larger chunks of 50 MB. I've seen that code work for files well over 1 GB in one chunk. But the file the server is getting stuck on is just 32 MB!

What is going on here? Is this a problem with FileChannel or Windows?

+1  A: 

It may be related to "Bug" ID 4938442: Insufficient System Resources When Copying Large Files with NIO FileChannels.

Evaluation: Not a bug. This is most likely a file-server (or possibly client) configuration issue.

CUSTOMER SUBMITTED WORKAROUND :

  • Don't use NIO; we'd prefer to avoid this workaround since NIO offers a significant performance boost for large files (at least when performing local disk-to-local disk copies)

  • We can transfer using a smaller number of bytes. The actual number of bytes that may be copied without encountering this error seems to differ on Windows XP and Windows 2000 server. Certainly a value of 32Mb appears to work.

polygenelubricants
You're a quick learner :o)
BalusC