最近项目中使用了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的更多相关文章

  1. java 基础知识学习 内存泄露(memory leak) VS 内存溢出(out of memory)以及内存管理

    内存泄露(memory leak) VS 内存溢出(out of memory) 内存溢出 out of memory,是指程序在申请内存时,没有足够的内存空间供其使用,出现out of memory ...

  2. java.util.zip.ZipException: invalid LOC header (bad signature)

    Debug on Server(Tomcat 9) 遇到这个exception: SEVERE: A child container failed during startjava.util.conc ...

  3. java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]

    本文为博主原创,未经允许不得转载: 被坑了好长时间的bug,差点就要重新配置环境,重新下载,重新开始的境遇.在此记录一下: 首先展示一下报错的异常: -Apr- ::] org.apache.cata ...

  4. 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 ...

  5. [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- ...

  6. 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 ...

  7. java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)异常解决方法

    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...

  8. java.lang.IllegalArgumentException,java.util.zip.ZipException 解决办法

    控制台错误信息: 严重: A child container failed during start java.util.concurrent.ExecutionException: org.apac ...

  9. java 从jar包中读取资源文件

    在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...

随机推荐

  1. MySQL数据库服务器 主从配置

    A B 为两台 MySQL 服务器,均开启二进制日志,数据库版本 MySQL 5.5 一.服务器参数   [A 服务器 192.168.1.100] server-id = 1 binlog-do-d ...

  2. easyui tree 判断点击的节点是否还存在子节点

    有些业务需求是要求tree一次性全部加载,有些是需要异步加载的. 如果是一次性全部加载的tree,那怎么判断点击的节点是否还存在子节点? function loadTree(){ $('#tree') ...

  3. MBR

    Mbr位于磁盘的0柱面,0磁头,1扇区. MBR       有三部分构成,主引导程序,硬盘分区表DPT和,硬盘的有效标志55AA.在512个字节的主引导扇区里. 主引导程序占446个字节,dpt占6 ...

  4. JS动画理论

    动画(Animation) 动画意味着随着时间而变化,尤其指视觉上的变化,包括位置.形态等的变化.运动基本上表现为物体随时间,发生位置上的变化:形态基本表现为大小.颜色.透明度.形状等随时间的变化. ...

  5. 练习2 A - ASCII码排序

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 输入三 ...

  6. JS获取select选中的值

    var oSel=oFl.getElementsByTagName('select')[0]; oSel.onchange=function(){ var indexselect=oSel.selec ...

  7. Gnome Tetravex

    zoj1008:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008 题目意思是有一个游戏,即给出一个图,该图是由n*n个 ...

  8. eclipse中tomcat内存溢出问题,报PermGen space

    场景 最近在eclipse中的tomcat服务器下放三个不同的应用程序,其中两个应用程序用到了各自的第三方jar包.刚开始时把这三个应用程序分别部署到各自的tomcat服务器运行,没问题.后来想通过第 ...

  9. javascript类型系统之Array

    原文:javascript类型系统之Array 目录 [1]数组创建 [2]数组操作 [3]继承的方法 [4]实例方法 数组转换 数组检测 栈和队列 排序方法 操作方法 位置方法 前面的话 数组是一组 ...

  10. AJAX 中Sys.WebForms.PageRequestManager的事件激发顺序 《转》

    AJAX 中Sys.WebForms.PageRequestManager的事件激发顺序 测试代码: 测试代码如下: <%@ Page Language="C#" AutoE ...