首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

MappedByteBuffer挟制释放后读取引发jvm crash

2012-10-07 
MappedByteBuffer强制释放后读取引发jvm crash?部分信息如下:## A fatal error has beendetected by the J

MappedByteBuffer强制释放后读取引发jvm crash

?

部分信息如下:

#

# A fatal error has beendetected by the Java Runtime Environment:

#

#? EXCEPTION_ACCESS_VIOLATION (0xc0000005) atpc=0x01b8d4d7, pid=10236, tid=8452

#

# JRE version: 6.0_18-b02

# Java VM: Java HotSpot(TM)Client VM (16.0-b09 mixed mode, sharing windows-x86 )

# Problematic frame:

# J? java.nio.DirectByteBuffer.get(I)B

#

# An error report file withmore information is saved as:

#D:\workspace_new\metamorphosis\metamorphosis-server\hs_err_pid10236.log

#

# If you would like to submit abug report, please visit:

#??http://java.sun.com/webapps/bugreport/crash.jsp

@Test

public void unmapAndRead()throws Exception {

? File file =new File("unmapAndRead.txt");

? FileChannel fileChannel =new RandomAccessFile(file,"rw").getChannel();

? MappedByteBuffer buf = fileChannel.map(MapMode.READ_WRITE, 0, 4096);

? buf.putInt(5);

? buf.force();

? this.unmap(buf);

? buf.get(2);//Crash occur

}

?

void unmap(finalMappedByteBuffer mappedByteBuffer) {

? try {

? ? if (mappedByteBuffer ==null) {

? ? return;

? }

? mappedByteBuffer.force();

? AccessController.doPrivileged(new PrivilegedAction<Object>() {

? @Override

? public Object run() {

? ? try {

? ? ? ?Method getCleanerMethod = ? ? ?mappedByteBuffer.getClass().getMethod("cleaner",new Class[0]);

? ? ? ?getCleanerMethod.setAccessible(true);

? ? ? ?sun.misc.Cleaner cleaner =

? ? ? ?(sun.misc.Cleaner)getCleanerMethod.invoke(mappedByteBuffer,new?Object[0]);

? ? ? ?cleaner.clean();

? ? }

? ? catch (Exception e) {

? ? ? ?e.printStackTrace();

? ? }

? ? return null;

? ?}

? });

?

?}

catch (Exception e) {

? ?e.printStackTrace();

}

}

?

热点排行