Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by r035198x View Post
    I suspect they meant finally though but you never know.
    Well, the Finalizer is to do with finalizing on gc. Could be wrong, though, since I haven't actually encountered a situation where this has been a problem. I really would, if I was the OP, use the analyser to dig into the Finalizers and see what it's holding onto.

  2. #22
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Sorry but I'm at work right now, and the boss would kill me if he know that I'm not working :D

    I removed finalize and I don't get any leaks about them...

    Also, which MySQL driver are you using?
    mysql-connector-java-5.1.8-bin.jar

    How much memory have you got assigned to your JVM when you run this?
    hm... how to check this?


    OK, let's start with the db side. Show how you're getting and releasing connections, statements and resultsets.
    connection class

    Java Code:
    public class ClientSQLConnect {
     
     static String[][] sPolja;
     static EkranClient client;
     
     public static String[][] Select(int iSize, String select) {
      
      try {
       povezi();
       s.executeQuery (select);
       ResultSet rs = s.getResultSet();
       int size = count(rs);
       sPolja = new String[size][iSize];
       rs.beforeFirst();
       int i = 0;
       while (rs.next()) {
        for (int j = 1; iSize+1 > j; j++) {
         sPolja[i][j-1] = rs.getString(j);
        }
        i++;
       }
       rs.close ( ); // close result set
       s.close ( ); // close statement
       if (conn != null)
       {
        try
        {
         conn.close ( );
        }
        catch (Exception e) { /* ignore close errors */ }
       }
      }
      catch (Exception e)
      {
       System.err.println ("CLIENT: Cannot connect to server "+e);
       //ponovnoPovezi();
      }
      return sPolja;
     }
     
     public static void Update(String update) {
    // 
      try {
       povezi();
       s = conn.createStatement();
       s.executeUpdate(update);
       s.close ( ); // close statement
       if (conn != null)
       {
        try
        {
         conn.close ( );
        }
        catch (Exception e) { /* ignore close errors */ }
       }
      }
      catch (Exception e)
      {
       System.err.println ("CLIENT: Cannot connect to server "+e);
      }
     }
     
     
     static Connection conn = null;
     static Statement s = null;
      
     public static Statement povezi() {
    
      ClientStart start = new ClientStart();
      String url = start.connect()[0];
      String userName = start.connect()[1];
      String password = "xxxxxx";
    
      try {
       Class.forName(start.connect()[2]).newInstance();
      } catch (InstantiationException e) {
       e.printStackTrace();
      } catch (IllegalAccessException e) {
       e.printStackTrace();
      } catch (ClassNotFoundException e) {
       e.printStackTrace();
      }
      try {
       conn = DriverManager.getConnection(url, userName, password);
      } catch (SQLException e) {
       e.printStackTrace();
      }
    
      try {
       s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
         ResultSet.CONCUR_UPDATABLE);
      } catch (SQLException e) {
       e.printStackTrace();
      }  
      return s;
     }
     
     public static int count(ResultSet rs){
      int rows = 0;
      try {
       rs.last();
       rows = rs.getRow();
      } catch (SQLException e) {
       e.printStackTrace();
      }
      return rows;
     }
    }
    SELECT... I call this select from other class
    Java Code:
    public class ClientSQLSelect {
     
     static Object[][] sqlData = null;
     static String sqlSelect = "";
     
     public static Object[][] getParametri(){
      
         sqlSelect = " SELECT id, vr_int, vr_str, opis FROM normo.parametri ";
      
         sqlData = ClientSQLConnect.Select(4, sqlSelect);
      return sqlData;
     }
    }
    Last edited by varann; 09-10-2009 at 02:44 PM.

  3. #23
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    close connections in a finally block.

    finally != finalize

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Sorry but I'm at work right now, and the boss would kill me if he know that I'm not working :D

    I removed finalize and I don't get any leaks about them...
    As r035198x says, finalize is not the same as the finally bit of a try/catch. Anyway, do as they say and close resource in a finally block for the try/catches. Do them in the order rs, s, conn, and wrap each in its own try/catch.

    This is unlikely to be your problem, though...could be, who knows right now.

    Quote Originally Posted by varann View Post
    mysql-connector-java-5.1.8-bin.jar

    hm... how to check this?
    How are you launching it? If it's just "java" on the commad line and you have no "Xmx" option supplied then you're using the default, which is quite low I think. Again, there's no guarantee this is the problem, but the gc might be thrashing occasionally trying to free up space. Try setting it to "-Xmx=256m".

    OK for the code, and again much of this is unlikely to be the cure, but tidying things up can help.

    There's no need for sPolja to be static. You only use it in the Select() method, so it may as well be local to that method. In addition, I'd use an ArrayList<String[]>. That way you don't have to determine the size of the result set beforehand, which involves reading in the entire result set in one go, rather than streaming it in in batches. I have no idea how big the result set is for this, but it can cause problems. You can always turn it into a String[][] at the end by simply doing toArray().

    Why are you rebuilding this each time?

    Java Code:
      ClientStart start = new ClientStart();
      String url = start.connect()[0];
      String userName = start.connect()[1];
      String password = "ad5utij7";

  5. #25
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Tnx guys for the motivation :)

    I have made some severe changes to the code. Removed many stupid things :). Next time I'll be more careful. I'm still not shure if it works, have to wait through the night, but it's much better.

    One more question. Since the program should work day and night (not yet, but it should be designed that way) how could I restart it every 12 hours?

    Tnx again.

  6. #26
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Why do you need to restart it?
    If it's functioning OK, and not leaking anything, it should merrily keep ticking away.

  7. #27
    varann is offline Member
    Join Date
    Sep 2009
    Posts
    8
    Rep Power
    0

    Default

    Finally good morning :) After 12 hours it's still working like it should.

    Why should I restart it? I'm still not 100% that all leaks are gone... It was just a thought. On Sunday I need to install the program. If a find out that it crashes after few days that's not good :)

    Another one... are there any arguments running the java that could help, beside Xmx?

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by varann View Post
    Finally good morning :) After 12 hours it's still working like it should.

    Why should I restart it? I'm still not 100% that all leaks are gone... It was just a thought. On Sunday I need to install the program. If a find out that it crashes after few days that's not good :)

    Another one... are there any arguments running the java that could help, beside Xmx?
    Well, take a heap dump every hour or two over today, and maybe again tomorrow. If the heap file gets bigger consistently then you might have a problem. Note, don't restart the program, since you've had it running for 12 hours it should have found its equilibrium, so you'll only see fluctuations rather than a steady increase.

    If the sizes of the files don't increase noticeably (they should go up and down a bit depending on whether the dump occurred before or afer a gc()) you should be fine.

    If it turns out you do need to restart, that's be the job of an external script, probably.

    Other than Xmx, if you now have a value you;re happy with then set Xms to it as well. That is the starting memory for the JVM. Setting them the same saves the JVM from having to grab extra memory as the heap fills up.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: 06-06-2009, 12:30 AM
  2. loop performance (no problem, just investigating)
    By CJSLMAN in forum New To Java
    Replies: 3
    Last Post: 01-18-2009, 04:02 AM
  3. Applet performance problem...
    By pmrenaud in forum Java Applets
    Replies: 0
    Last Post: 01-07-2009, 04:47 PM
  4. performance problem on osx
    By coldnebo in forum Advanced Java
    Replies: 3
    Last Post: 08-01-2008, 10:39 PM
  5. Performance Of Collections
    By thomasprabu in forum Advanced Java
    Replies: 0
    Last Post: 01-05-2008, 12:17 PM

Posting Permissions

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