RandomAccessFile raf;
try {
raf = new RandomAccessFile(IncBspConstants.MEMORY_SHARE_FILE+"_part_"+peer.getPeerIndex(), "rw");
FileChannel fc = raf.getChannel();
mbb = fc.map(MapMode.READ_WRITE, 0, bufferSize);
readData() ;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
private void readData(){
try{
int flag = mbb.get() ; //取读写数据的标志
if(mbb==null) LOG.info(" mbb is NULL! " + "flag :" + flag) ;
if(flag!=1)
mbb.clear() ;
else //=1说明已经写入则读取
{
dataLength = mbb.getInt() ;
buf = new byte[dataLength] ;
mbb = (MappedByteBuffer) mbb.get(buf);
}
} catch (Exception e) {
e.printStackTrace();
}
}
bufferSize是200M
此外这个JVM的启动参数设为: -Xmx2304m, 这个没问题,没有超过JVM的堆内存限制。
但是一运行到 mbb = fc.map(MapMode.READ_WRITE, 0, bufferSize) 时就报如下错误:
java.io.IOException: Map failed
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:849)
at org.apache.hama.bsp.incBsp.IncGraphProcessor.<init>(IncGraphProcessor.java:45)
at org.apache.hama.graph.GraphJobRunner.setupFields(GraphJobRunner.java:454)
at org.apache.hama.graph.GraphJobRunner.setup(GraphJobRunner.java:123)
at org.apache.hama.bsp.BSPTask.runBSP(BSPTask.java:170)
at org.apache.hama.bsp.BSPTask.run(BSPTask.java:144)
at org.apache.hama.bsp.GroomServer$BSPPeerChild.main(GroomServer.java:1243)
Caused by: java.lang.OutOfMemoryError: Map failed
at sun.nio.ch.FileChannelImpl.map0(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:846)
... 6 more
是buffersize设的太大么? 这里我就是需要进行大量数据的共享啊,所以设的很大,可是一初始化就报错了。。。。
------解决思路----------------------
楼主你的机器是32位还是64位?
如果是32位你把-Xmx2304m 设置小一点比如512m,然后看看问题是否解决。