java.lang.OutOfMemoryError:文件上的Java堆空间操作

时间:2019-03-18 21:37:00

标签: java tomcat

我想从文本文件中读取数据,该文件是.html中的10-K SEC报告(大小约为3MB)。首先,我编写了具有这样功能的代码以准备文件:

p6 = Pattern.compile("$| |&#8212|​|—|’| ");
 private void preparerep() {
     System.out.println("free m " + Runtime.getRuntime().freeMemory()/1048576);
        System.out.println("used m " + (Runtime.getRuntime().maxMemory()-Runtime.getRuntime().freeMemory())/1048576);
        System.out.println("all m " +  Runtime.getRuntime().maxMemory()/1048576);

        StringBuffer modified = new StringBuffer();
        m4 = p6.matcher(rawrep);
        while(m4.find())m4.appendReplacement(modified, " ");
        m4.appendTail(modified);
        rawrep = modified.toString();
        rawrep = rawrep.toLowerCase();
        pages = rawrep.split("page-break");
         System.out.println("found pages  " + pages.length);
 }

此代码循环执行。问题是,在对不同文件执行了几次之后,它在第while(m4.find())m4.appendReplacement(modified, " ");行中抛出了Out of Memory错误代码。我的代码中是否存在内存泄漏?还是只是我的服务器没有足够的内存(tomcat为此应用程序仅提供了180mb)?如果是服务器故障,如何在Ubuntu中为tomcat设置更多的堆大小?

0 个答案:

没有答案
相关问题