Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20

    Lightbulb Unanswered: Memory leak with DB2 9.7 jdbc driver

    Hello,

    We want to upgrade to DB2 9.7.
    But we keep getting memory leaks in java.

    We have tried the jdbc3 and jdbc4 drivers (latest _3a version march 2011) but both have the same problem.
    If we run the code underneath, memory usage keeps on going up until we get an outofmemory error

    Code:
          Connection dbConnection = DriverManager.getConnection("jdbc:db2://server:50000/database", "username", "password");
          
          dbConnection.setAutoCommit(false);
          
          PreparedStatement insertStatement = dbConnection.prepareStatement("INSERT INTO table (ID, TIMESTAMP_RECEIVED) VALUES(?, ?)");
          
          int i = 0;
          while (true) {
            
            insertStatement.setString(1,""+i++);
            insertStatement.setTimestamp(2,new Timestamp(System.currentTimeMillis()));
            
            insertStatement.execute();
            insertStatement.clearParameters();
            insertStatement.clearWarnings();
           
            dbConnection.commit();
            if (i % 10000 ==0){
              System.out.println("inserts = " + i);
            }
          }
    Did someone also have these problems, or does someone know what's going wrong?

    Thanks in advance, Tinie

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Which fixpack are you using for the server and the client driver? Have you tried FP 3a?
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    What is the meaning of "true" in "while (true)"?
    Didn't the while loop get into infinite loop?

  4. #4
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20
    Quote Originally Posted by Marcus_A View Post
    Which fixpack are you using for the server and the client driver? Have you tried FP 3a?
    Whe are using the latest driver.
    Is there a difference between a server or client driver?

  5. #5
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20
    Quote Originally Posted by tonkuma View Post
    What is the meaning of "true" in "while (true)"?
    Didn't the while loop get into infinite loop?
    It is our purpose to have an infinite loop, so we can test the memory leak problem.
    This app is just a test for the memory leak error.

  6. #6
    Join Date
    Jan 2009
    Location
    Zoetermeer, Holland
    Posts
    746
    Are you sure this is a memory leak? Did you try this piece of code on other databases without trouble?
    My java knowledge is limited but is seems to me that you are creating new java-objects and as far as the garbage-collector is conserned they are all used so cannot be touched. This goes as far as your jvm-heap, but a memory leak????

  7. #7
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20
    Quote Originally Posted by dr_te_z View Post
    Are you sure this is a memory leak? Did you try this piece of code on other databases without trouble?
    My java knowledge is limited but is seems to me that you are creating new java-objects and as far as the garbage-collector is conserned they are all used so cannot be touched. This goes as far as your jvm-heap, but a memory leak????
    I have run the test app against an oracle database with the ojdbc14 jdbc driver.
    Here everything works fine.
    After the memory usage has climbed up to 5mb it falls down to 1mb. And this repeats over and over again.
    While with the db2 driver the memory usage only climbs up.

  8. #8
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Is ID a numeric column?

  9. #9
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20
    Quote Originally Posted by shammat View Post
    Is ID a numeric column?
    No, ID is a VARCHAR

  10. #10
    Join Date
    Nov 2010
    Location
    The Netherlands
    Posts
    20
    It seems we have found the problem.
    It wasn't the db2 jdbc driver, but the hardware.

    We are doing the same test, with the same harddrive, on other machines and
    the memory leak doesn't appear anymore.

Tags for this Thread

Posting Permissions

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