NIO file channel transfer problem on iSeries
I'm having a problem with some Java NIO code running on an iSeries box (JDK 1.5). Basically the code is splitting a file up into chunks part of a file to another smaller files. The same code has been operating on other iSeries boxes for some time with no problems. Here's the code snippet:
//copy original data file content to temp file
long startPos = dataFile.length() - remaining;
long transferSize = maxSizeBytes - size;
size += inChannel.transferTo(startPos, transferSize, outChannel); //exception here
remaining -= size;
Here's the stack trace:
Caused by: java.io.IOException: Operation not supported. Map failed
at java.lang.Throwable.<init>(Throwable.java:196)
at java.lang.Exception.<init>(Exception.java:41)
at java.io.IOException.<init>(IOException.java开发者_StackOverflow社区:40)
at sun.nio.ch.FileChannelImpl.map0(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:742)
at sun.nio.ch.FileChannelImpl.transferToTrustedChannel(FileChannelImpl.java:448)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:521)
... 11 more
I've done some investigation and the causes so far (file permissions of parent directory, out of memory, shared memory control QSHRMEMCTL switched off, use of SAN) have all proved unsuccessful.
Anyone have any experience of this particular problem?
Thanks, Brad.
It sticks in my mind that reaching the file handle limit can result in non-obvious exceptions being raised by the JVM.
Check to see if you have enough file handles available. ulimit
will tell you how many are at your disposal. (Of course, you'll want to know this number for the user the JVM is running under if it is a daemon.) This problem would also be system/user specific, which kinda fits your description of the fact this runs elsewhere just fine.
According to this thread (which supports the argument with reference to the NIO source), the likely cause is an out of memory condition.
OK, another shot: Could you post more of your code? Like the initialization of all viables and your control loop. Even though you are saying works elsewhere, I have to wonder about a few things and so have disregarded that.
1: long startPos = dataFile.length() - remaining;
2: long transferSize = maxSizeBytes - size;
3: size += inChannel.transferTo(startPos, transferSize, outChannel); //exception here
4: remaining -= size;
- Is
remaining
initialized todataFile.length()
outside of your loop? If not, then that is going to blow up from the start all the time. size
might be probably better namedbytesTransfered
. I found myself getting a bit mixed up with that.- You don't need both
remaining
andsize
variables. One or the other should suffice - Is
maxSizeBytes
initialized to a value <=dataFile.length()
- Can you log
startPos
,transferSize
, anddataFile.length()
? I'm wondering if maybe you are inadvertently- passing a
transferSize
larger thandataFile.length()
- passing a
startPos
larger thandataFile.length()
- passing a
精彩评论