Results 1 to 3 of 3
  1. #1
    vishnu22001 is offline Member
    Join Date
    Mar 2011
    Location
    Sriharikota
    Posts
    3
    Rep Power
    0

    Default Runtime Errror in Java alpplication for Processing squid log files..

    Here !!! is the code ..


    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import java.text.*;
    class readlog
    {
    public readlog()
    { ; }
    public static void main(String[] args)
    {
    (new readlog()).read();
    }
    public void read()
    {
    String line = "";
    String logDet[];
    double val;
    String driver = "com.mysql.jdbc.Driver";
    Connection con=null;
    ResultSet rst=null;
    PreparedStatement stmt=null;
    try{
    String url="jdbc:mysql://localhost:3306/slog";
    String user="admin";
    String pass="admin";
    Class.forName(driver).newInstance();
    con=DriverManager.getConnection(url,user,pass);
    //stmt=con.prepareStatement("Insert Into sep values (?,?,?,?,?,?,?,?,?,?,?,?)");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }try
    {
    int a,d;
    long s;
    DateFormat formatter;
    String temp[]={"jan","feb","mar","apr","may","jun","jul","aug", "sep","oct","nov","decm"};
    BufferedReader br = new BufferedReader (new FileReader("access.log"));
    while((line = br.readLine()) != null)
    {
    logDet = mySplit(line.trim());
    a=logDet[0].indexOf(".");
    s=Long.parseLong(logDet[0].substring(0,a));
    java.util.Date date=new java.util.Date(s*1000);
    formatter= new SimpleDateFormat("WW MM dd kk:mm:ss zz yyyy");
    String s1=formatter.format(date);
    String token[] =s1.split(" ");
    String dev=token[5]+"-"+token[1]+"-"+token[2];
    d=Integer.parseInt(token[1])-1;
    // System.out.println(""+temp[d]);
    stmt=con.prepareStatement("Insert Into"+" "+temp[d]+" values (?,?,?,?,?,?,?,?,?,?,?,?)");
    stmt.setString(1,logDet[0]);
    stmt.setString(2,logDet[1]);
    stmt.setString(3,logDet[2]);
    stmt.setString(4,logDet[3]);
    stmt.setInt(5,Integer.parseInt(logDet[4]));
    stmt.setString(6,logDet[5]);
    stmt.setString(7,logDet[6]);
    stmt.setString(8,logDet[7]);
    stmt.setString(9,logDet[8]);
    stmt.setString(10,logDet[9]);
    stmt.setString(11,dev);
    stmt.setString(12,token[3]);
    stmt.executeUpdate();
    }
    }
    catch(Exception e)
    {
    System.out.println(e);
    e.printStackTrace();
    }
    }
    public String [] mySplit(String line)
    {
    int len =0;
    String splitString[] = (line.trim()).split(" ");
    String returnString[] = new String[50];
    for(int i=0;i<splitString.length;i++)
    {
    if((splitString[i]).trim().length() > 0)
    {
    returnString[len] = splitString[i];
    len++;
    }
    }
    return returnString;
    }
    }

    when i compile it i get no errors and whrn i run this.. after inserting 40000(approx) records i get this error

    D:\v>java readlog
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.LinkedHashMap.createEntry(Unknown Source)
    at java.util.LinkedHashMap.addEntry(Unknown Source)
    at java.util.HashMap.put(Unknown Source)
    at sun.util.resources.OpenListResourceBundle.loadLook up(Unknown Source)
    at sun.util.resources.OpenListResourceBundle.loadLook upTablesIfNecessary(Unknown Source)
    at sun.util.resources.OpenListResourceBundle.handleGe tObject(Unknown Source)
    at sun.util.resources.TimeZoneNamesBundle.handleGetOb ject(Unknown Source)
    at java.util.ResourceBundle.getObject(Unknown Source)
    at java.util.ResourceBundle.getObject(Unknown Source)
    at java.util.ResourceBundle.getStringArray(Unknown Source)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( Unknown Source)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( Unknown Source)
    at java.util.TimeZone.getDisplayNames(Unknown Source)
    at java.util.TimeZone.getDisplayName(Unknown Source)
    at java.text.SimpleDateFormat.subFormat(Unknown Source)
    at java.text.SimpleDateFormat.format(Unknown Source)
    at java.text.SimpleDateFormat.format(Unknown Source)
    at java.text.DateFormat.format(Unknown Source)
    at readlog.read(readlog.java:51)
    at readlog.main(readlog.java:12)



    please any one help me out
    thanks in advance....
    Last edited by vishnu22001; 03-05-2011 at 08:22 AM.

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    with that wasteful use of (string) objects in the code it shouldn't be surprising if sooner or later a OutOfMemoryError is thrown. as a quick workaround you can start your jvm with -Xms<size> specifying the initial Java heap size and -Xmx<size> for the maximum Java heap size.

    can you please post some lines of the file access.log, so i can run the code and perhaps improve the code without changing the heap size.
    Last edited by j2me64; 03-05-2011 at 10:39 AM.

  3. #3
    vishnu22001 is offline Member
    Join Date
    Mar 2011
    Location
    Sriharikota
    Posts
    3
    Rep Power
    0

    Default

    here is the log

    1284851125.760 12 172.16.100.217 TCP_DENIED/407 2082 GET http://oscex-en.url.trendmicro.com/P...DD2D70685F1F45 - NONE/- text/html

    1284851125.776 13 172.16.100.217 TCP_DENIED/407 2082 GET http://oscex-en.url.trendmicro.com/P...DD2D70685F1F45 - NONE/- text/html

Similar Threads

  1. Java application for processing Squid proxy logs
    By Unnel in forum New To Java
    Replies: 11
    Last Post: 03-05-2011, 03:50 AM
  2. Compile errror
    By kiz106 in forum New To Java
    Replies: 1
    Last Post: 05-11-2010, 09:21 AM
  3. tomcat-errror
    By isabolic in forum Java Servlet
    Replies: 0
    Last Post: 03-29-2010, 12:18 PM
  4. grep on multiple files using Runtime.getRuntime().exec()
    By cprash.aggarwal in forum Advanced Java
    Replies: 3
    Last Post: 02-11-2009, 06:55 AM
  5. Replies: 0
    Last Post: 07-18-2008, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •