最近项目中使用了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. .NET Framework(二)

    在上一篇的随笔中,我们在理论层面上大致说明了.NET Framework的工作机制,内容的确比较晦涩难懂,但是还是希望大家有时候可以看看.我个人觉得,编程不是一味的敲代码,当自己遇到瓶颈的时候,可以多 ...

  2. Mrakdown文本编辑器

    http://www.csdn.net/article/2014-05-05/2819623 WMD WMD (wmd-editor)是一个简单轻量级的HTML编辑器,使用的是 Markdown 文本 ...

  3. Connect mysql on Linux from Windows

    ON LINUX: 1 sudo apt-get install mysql-server 2 sudo apt-get install python-dev 3 sudo apt-get insta ...

  4. K - 计算球体积

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

  5. 工作总结:WPF技术讲解(大纲)

    一.WPF的历史 首先给大家讲述一下Winform的发展里程来展示WPF的历史,告诉大家WPF是在什么背景下诞生的. 二.WPF的特性 与MFC.Windows相比,WPF具有3D呈现特性,XMAL是 ...

  6. Preparing for the Contest

     Codeforces Round #222 (Div. 1)B:http://codeforces.com/contest/377/problem/B 题意:m个任务,每个任务会有一个复杂度,然后给 ...

  7. ios入门之c语言篇——基本函数——1——随机数生成

    1.随机数函数 参数返回值解析: 参数: a:int,数字范围最小值: b:int,数字范围最大值: 返回值: 1:闰年: 0:非闰年: 备注: a-b的绝对值不能超过int的最大值(65535); ...

  8. Unity 用C#脚本读取JSON文件数据

    读取JSON文件数据网上有很多方法吗,这里采用SimpleJSON,关于SimpleJSON的介绍参考以下链接:http://wiki.unity3d.com/index.php/SimpleJSON ...

  9. bzoj2789

    这种题目肯定是先把一个当做标准串根据标准串得出一个初始串是怎么排列的,然后求逆序对数就可以了但是因为有重复,我们不知道标准串中的一个数到底是由原来哪个字母交换来的但是我们可以猜,不难贪心得到对于标准串 ...

  10. COJ 2108 Day7-例1

    Day7-例1 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述   在计算机中,CPU只能和高速缓存Cache直接交换数据.当 ...