java.util.jar.JarFile cause native heap memory leak
来源:互联网 发布:java开发erp系统 编辑:程序博客网 时间:2024/06/09 12:08
最近项目中使用了JarFile 这个类 来load jar包中的 configuration,大致的情况如下
public void processJarEntries(JarFile paramJarFile, ZipEntryFilter paramZipEntryFilter, ZipEntryProcessor paramZipEntryProcessor)
{
for (Enumeration localEnumeration = paramJarFile.entries(); localEnumeration.hasMoreElements(); ) {
ZipEntry localZipEntry = (ZipEntry)localEnumeration.nextElement();
if (paramZipEntryFilter.accept(localZipEntry))
paramZipEntryProcessor.process(paramJarFile, localZipEntry);
}
}
ZipEntryFilter 是过滤jar文件中不相关的文件 ZipEntryProcessor 用来做具体对找到的文件操作
问题引入: 此时会通过JarFile中的 两个method 来 遍历jar包中的文件 hasMoreElements & nextElment
在多线程处理的情况下引起 native heap memory leak 可以 通过 pmap -ax pid|grep heap 来查看
解决:
JarInputStream localJarInputStream = null;
localJarInputStream = new JarInputStream(getBufferedInputStream(paramFile));
public static InputStream getBufferedInputStream(File paramFile) throws IOException {
FileInputStream localFileInputStream = new FileInputStream(paramFile);
return new BufferedInputStream(localFileInputStream);
}
public void processJarEntries(JarInputStream paramJarInputStream, JarEntryProcessor paramJarEntryProcessor) {
ZipEntry localZipEntry = paramJarInputStream.getNextEntry();
while (localZipEntry != null) {
paramJarEntryProcessor.process(localZipEntry);
localZipEntry = paramJarInputStream.getNextEntry();
}
paramJarEntryProcessor.completeProcess();
}
此bug可以在oracle官网中查到
- java.util.jar.JarFile cause native heap memory leak
- java.util.jar.JarFile翻译
- Android native heap memory leak 实战(二) --- DDMS
- Android native memory leak debug
- java Memory Leak
- Handling Java Memory Leak
- Java的Memory leak
- Java Memory Leak Test
- JVM的Heap Memory和Native Memory
- JVM的Heap Memory和Native Memory
- android memory leak ==java memory leak
- Java Heap Memory
- 通过分析Heap Dump 来了解 Memory Leak ,Retained Heap,Shallow Heap
- Howto find native code memory leak in Android
- How to debug native memory leak in anroid
- FAQ05872]如何用DDMS分析native memory leak
- java打包异常2:Invalid or corrupt jarfile test.jar
- Memory Leak
- UITableView cell自定义视图中插入Table实现复杂界面
- 17-php计算器
- Linux下的source、export
- 不要试图和下属做朋友
- python as lambda fiter的使用
- java.util.jar.JarFile cause native heap memory leak
- poj 1012 约瑟夫
- The content of the adapter has changed but ListView did not receive a notification
- 用户sa登陆失败 microsoft sql server 错误18456
- UITableView cell自定义视图中插入UITableView
- 黑马程序员 交通灯管理系统的学习
- IntPtr与自定义结构互转
- Maven打包,并设置main方法启动
- 开通一个博客,还没有想好要写什么