DirectByteBuffer
来源:互联网 发布:http json 接口规范 编辑:程序博客网 时间:2024/04/29 11:29
DirectBuffer 通过免去中间交换的内存拷贝, 提升IO处理速度;也就是常说的zero-copy
- ByteBuffer
- HeapByteBuffer
- MappedByteBuffer
- MappedByteBuffer.map(int mode,long position,long size);
READ_ONLY只读试图修改得到的缓冲区将导致抛出 ReadOnlyBufferExceptionREAD_WRITE读/写对得到的缓冲区的更改最终将传播到文件;该更改对映射到同一文件的其他程序不一定是可见的PRIVATE专用对得到的缓冲区的更改不会传播到文件,并且该更改对映射到同一文件的其他程序也不是可见的;相反,会创建缓冲区已修改部分的专用副本
分配java.nio.ByteBuffer.allocateDirect释放sun.nio.ch.DirectBuffer.cleaner().clean()
可以通过参数 -XX:MaxDirectMemorySize= 设置其可使用的最大内存大小,当未设置时默认同 -Xmx 的大小。
各种应用
BigMemoryhttp://terracotta.org/products/bigmemoryBigMemory stores “big” amounts of data in machine memory for ultra-fast accessDirectMemoryhttp://incubator.apache.org/directmemory/Apache DirectMemory is a multi layered cache implementation featuring off-heap memory management (a-la BigMemory) to enable efficient handling of a large number of java objects without affecting jvm garbage collection performanceHugeCollectionshttps://code.google.com/p/vanilla-java/wiki/HugeCollectionsIf you want to efficiently store large collections of data in memory. This library can dramatically reduce Full GC times and reduce memory consumption as well
OutOfMemoryError
和 DirectBuffer 相关的内存泄漏参看Study_Java_HotSpot_OOME
参考资料
[1]. http://blog.csdn.net/fancyerii/article/details/7655451
[2]. http://lixjluck.iteye.com/blog/1130455
[3]. http://www.zhurouyoudu.com/index.php/archives/470/
import java.lang.reflect.Method;import java.nio.ByteBuffer;import java.security.AccessController;import java.security.PrivilegedAction;/** * {@link DirectByteBufferCleaner} * * @author <a href=mailto:zhong.lunfu@gmail.com>zhongl</a> * @created 2011-1-14 */public final class DirectByteBufferCleaner { private DirectByteBufferCleaner() {} public static void clean(final ByteBuffer byteBuffer) { if (!byteBuffer.isDirect()) return; try { Object cleaner = invoke(byteBuffer, "cleaner"); invoke(cleaner, "clean"); } catch (Exception e) { /* ignore */ } } private static Object invoke(final Object target, String methodName) throws Exception { final Method method = target.getClass().getMethod(methodName); return AccessController.doPrivileged(new PrivilegedAction<Object>() { @Override public Object run() { try { return method.invoke(target); } catch (Exception e) { throw new RuntimeException(e); } } }); }}
0 0
- DirectByteBuffer
- DirectByteBuffer
- java之HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- java之HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- java之HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- java之HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- java之HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- java HeapByteBuffer&DirectByteBuffer以及回收DirectByteBuffer
- Bytebuffer 和DirectByteBuffer
- HeapByteBuffer和DirectByteBuffer
- DirectByteBuffer内存申请与释放
- 堆外内存DirectByteBuffer剖析
- 堆外内存之DirectByteBuffer
- NIO DirectByteBuffer 内存泄露的测试
- java-nio之HeapByteBuffer与DirectByteBuffer详解
- 堆外内存之 DirectByteBuffer 详解
- java学习-【转】NIO DirectByteBuffer 内存泄露的测试
- java nio中,HeapByteBuffer与DirectByteBuffer的区别
- tomcat 7如何配置线程池
- rg.hibernate.ObjectNotFoundException: No row with the given identifier exists
- aix下设置自动启动、关闭oracle
- Timer 计时器进入后台仍能继续运行
- android效果集合[链]
- DirectByteBuffer
- Activity与service 之间的通信
- C++入门系列 拷贝构造函数 拷贝赋值函数
- Android 工具类积累
- 深入理解按位异或运算符
- ids for this class must be manually assigned before calling save()
- extjs 文本框后加一个按钮或 文字
- C/C++---static函数,static成员函数,static变量,static成员变量 再来理一理
- 转自: http://blog.csdn.net/xiaxiaorui2003/article/details/3838631