java.util.jar.JarFile cause native heap memory leak
最近项目中使用了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 基础知识学习 内存泄露(memory leak) VS 内存溢出(out of memory)以及内存管理
内存泄露(memory leak) VS 内存溢出(out of memory) 内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory ...
- java.util.zip.ZipException: invalid LOC header (bad signature)
Debug on Server(Tomcat 9) 遇到这个exception: SEVERE: A child container failed during startjava.util.conc ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]
本文为博主原创,未经允许不得转载: 被坑了好长时间的bug,差点就要重新配置环境,重新下载,重新开始的境遇.在此记录一下: 首先展示一下报错的异常: -Apr- ::] org.apache.cata ...
- Tomcat启动报错:org.apache.catalina.LifecycleException: Failed to start component...java.util.zip.ZipException: error in opening zip file
1.项目环境 IntelliJ IDEA2018.1.6 apache-tomcat-8.0.53 基于springboot开发的项目 maven3.5.3 2.出现问题 从svn同步下项目 启动to ...
- [java ] java.util.zip.ZipException: error in opening zip file
严重: Failed to processes JAR found at URL [jar:file:/D:/tools/apache-tomcat-7.0.64_2/webapps/bbs/WEB- ...
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/xiaozao_web]]
二月 20, 2017 11:30:28 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRul ...
- java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)异常解决方法
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
- java.lang.IllegalArgumentException,java.util.zip.ZipException 解决办法
控制台错误信息: 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apac ...
- java 从jar包中读取资源文件
在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...
随机推荐
- 关于浮动float属性和position:absolute属性的区别
最近返回头看了很多书籍,一直在纠结float属性和absolute绝对定位的区别和使用的情况,给大家分享一下自己的心得和体会吧. 1,float属性 float属性意义是让元素拜托独占一行的霸道总裁, ...
- magento后台 Fatal error: Call to a member function getId() on a non-object in错误
后台分类管理出现错误 Fatal error: Call to a member function getId() on a non-object in 在数据库中运行以下sql语句 INSERT I ...
- php foreach 使用&(与运算符)引用赋值要注意的问题
首先了解一下“引用赋值”,看一个例子: <?php <?php $a=123; $a=123; $b=$a; $b=&$a; $a=321; $a=321; echo"$ ...
- unix 环境高级编程 读书笔记与习题解答第四篇
第一章 第六节 第一小节 这一章没有程序设计和API方面的深入学习,而是注重介绍了unix操作系统中的原始数据类型和系统原型函数,错误处理方面的知识. ____unistd.h____ 该文件包含了u ...
- Linux 查看 80 端口的占用情况
lsof -i:端口号 eg: lsof -i:80 lsof -i:21 [root@localhost ~]# lsof -i: COMMAND PID USER FD TYPE DEVICE S ...
- SharePoint 获取Lookup 字段的值
获取某个List里的Lookup字段的值是很普遍的事,那么我们将它封装起来 获取Lookup字段值的方法: /// <summary> /// To get lookup field Id ...
- text-decoration属性
一.在CSS1中,text-decoration有六个值: text-decoration:none //默认,定义标准的文本,没有任何样式,正常显示 text-decoration:underli ...
- 【Web Service】WSDL文档
WSDL文档仅仅是一个简单的XML文档. 它包含一系列描述某个web service的定义. WSDL WSDL 是基于 XML 的语言,用于描述 Web services 以及如何访问它们. WSD ...
- 5. repeater图片放大
当把鼠标放在一张小图片上时,图片会自动放大,离开时它变小. 我们在静态页面中可以用jQuery来操作.如下为html中的源码. <!DOCTYPE html PUBLIC "-//W3 ...
- Hibernate 配置详解(5)
9) hibernate.batch_fetch_style: 该配置是hibernate4.2.0新添加的,使用这个设置可以配置hibernate在做batch-fetch的时候,生成SQL的策略. ...