troubleshooting Question

search a pattern in a large file using java

Avatar of pvinodp
pvinodp asked on
JavaSearch Engine Optimization (SEO)
20 Comments1 Solution650 ViewsLast Modified:
Following is my code in a particular function.
 
     Scanner sc = new Scanner(new File("/exports/nos_issues/9518/aaa_.log"));
      String str="10:37:10.719 [net.jradius.freeradius.FreeRadiusProcessor(29)] DEBUG net.jradius.log.Log4JRadiusLogger - >>> packets";
      Pattern ptr = Pattern.compile(str);
      long toto=0;
      try{
         while(sc.findWithinHorizon(ptr ,0000) != null)
            toto++;
      }finally{
         sc.close();
      }
     
      System.out.println(toto);
     

I get the following error :

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.nio.HeapCharBuffer.<init>(HeapCharBuffer.java:39)
      at java.nio.CharBuffer.allocate(CharBuffer.java:312)
      at java.util.Scanner.makeSpace(Scanner.java:816)
      at java.util.Scanner.readInput(Scanner.java:771)
      at java.util.Scanner.findWithinHorizon(Scanner.java:1659)
      at Cl.main(Cl.java:38)

in the class Cl the line number 38 points to sc.close();
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 20 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros