0

I am using java.io To read Log Files and grep for ERROR/WARN etc... using

//FileManipulator class
   public static List<String> execute(String command) throws IOException{
            List<String> output = new ArrayList<String>();

            Process process = Runtime.getRuntime().exec(new String[] { "bash", "-c", command });

            InputStream input = process.getInputStream();
            InputStreamReader isr = new InputStreamReader(input);
            BufferedReader br = new BufferedReader(isr);

            String line = null;
            while ((line = br.readLine()) != null){
                output.add(line);
            }   
            input.close();

            return output;
        }

And I am getting this excption while running the same

Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOfRange(Arrays.java:2694)
        at java.lang.String.<init>(String.java:203)
        at java.io.BufferedReader.readLine(BufferedReader.java:349)
        at java.io.BufferedReader.readLine(BufferedReader.java:382)
        at com.citi.muni.msdc.sanity.util.FileManipulator.execute(FileManipulator.java:220)
        at com.citi.muni.msdc.sanity.util.FileManipulator.grepWarnings(FileManipulator.java:300)

So it seems some of the files may be too large in size to process, Can some one suggest how I can edit my current approach to stop getting the heap issue.

Thanks SK

trincot
  • 317,000
  • 35
  • 244
  • 286
SHinny
  • 99
  • 1
  • 2
  • 12

1 Answers1

0

How big are the files you are trying to read?

You can try and increase heap size. Look here: Increase heap size in Java

Community
  • 1
  • 1
Jani
  • 190
  • 2
  • 12