0

I have socket application with the code snippet as below. I have ensured that the socket is closed in a finally block. I just had a Full GC I guess either yesterday or the day before. Then I compare the instances of the socket via jmap before this FGC and today which is after the FGC but the instances did not decrease but keep increasing? What could be the cause or is it wrong to refer to jmap? Another thing which is that after the full GC the Old Generation does not become 0?

BoneCP connectionPool = null;
  class ConnectionHandler implements Runnable {
    Connection dbconn = null;
    public void run() { // etc
     BufferedWriter writeBuffer = null;
     BufferedReader readBuffer = null;
     String capturedMessage="";
     try{
        dbconn = connectionPool.getConnection();
        dbconn.setAutoCommit(false);
        while ((nextChar=readBuffer.read()) != -1){          
          capturedMessage += (char) nextChar;
          if (nextChar == '*'){
           try{

                ///For select we do this  
                Statement stmt2 = null;
                stmt2 = dbconn.createStatement(); 
                String selectQuery2= .........
                ResultSet rs2 = stmt2.executeQuery(selectQuery2);
                if(rs2.next()){
                }
                try{
                 if ( rs2!= null ){  
                     rs2.close();
                 }   else{
                 System.out.println("No rs2 exist");
                 }
                 if ( stmt2!= null ){ 
                      stmt2.close();
                 }   else{
                 System.out.println("No stm2 exist");
                 }
                }catch(SQLException ex)
                {   
                System.out.println("SQLException has been caught for stmt2");
                ex.printStackTrace(System.out);
                }
                funct1();
                funct2();
                dbconn.commit
           }
           catch (SQLException ex){
                ex.printStackTrace(System.out);
                 try{  
                    dbconn.rollback();
                 }
                catch (Exception rollback){  
                   rollback.printStackTrace(System.out);
                }
           }
           catch (Exception e){
               e.printStackTrace(System.out);
               try{  
                  dbconn.rollback();
               }
               catch (Exception rollback){  
                  rollback.printStackTrace(System.out);
               }
           }
           finally{
           }
     }
     catch (SocketTimeoutException ex){
           ex.printStackTrace();
     }
     catch (IOException ex){
           ex.printStackTrace();
     }
     catch (Exception ex){
           ex.printStackTrace(System.out);
     }    
     finally{
        try{
         if ( dbconn != null ){
           dbconn.close();
         }
         else{
          System.out.println("dbConn is null in finally close");
         }
        }
        catch(SQLException ex){
            ex.printStackTrace();
        }
        try{
          if ( writeBuffer != null ){
            writeBuffer.close();

          }
          else{
            System.out.println("writeBuffer is null in finally close");
          }
        }
        catch(IOException ex){
            ex.printStackTrace(System.out);
        }
       }
      }
Robin Green
  • 29,408
  • 13
  • 94
  • 178
user2711681
  • 275
  • 6
  • 16

1 Answers1

1

I see you are using BoneCP - so am I. I found a bug in BoneCP which made my application open far too many connections. I'm not sure exactly how I fixed it, I basically threw everything I could think of at the problem, and I'm not sure which change(s) fixed it, but upgrading to the latest BoneCP snapshot might help.

Robin Green
  • 29,408
  • 13
  • 94
  • 178
  • yes my resultset in the jmap also keep growing. I got a problem there too I have close all possible resultset and statement yet it keep growing. I checked my current version is using this bonecp-0.7.1.RELEASE. So what version using is it bonecp-0.7.8.RELEASE which stated in their link here as stable or bonecp-0.8.0.RELEASE http://jolbox.com/index.html?page=http://jolbox.com/download.html. Do you think I must stop my application first or just replace .jar file will do ? But in this link http://jolbox.com/index.html?page=http://jolbox.com/download.html there is no 0.7.8 version ? – user2711681 Dec 02 '13 at 02:18
  • Unfortunately it is the latest release (0.8.0) that I found this bug in, that's why I suggested you use the latest SNAPSHOT, not the latest release. Yes, you will almost certainly need to restart your application. – Robin Green Dec 02 '13 at 08:22
  • @Which is the link to the snapshot? I am not sure can you guide me the exact version. So after using the snapshot does it help? – user2711681 Dec 02 '13 at 08:27
  • It seems to help, yes, I can't reproduce this problem any more. Here is the snapshot: http://oss.sonatype.org/content/repositories/snapshots/com/jolbox/bonecp/0.8.1-SNAPSHOT/bonecp-0.8.1-20131105.191813-1.jar – Robin Green Dec 02 '13 at 08:29
  • Actually what as the problem you have having? I am using the old version 0.7.1 do you think I should move to this version? Is it anything to do with the pooling and resultset? – user2711681 Dec 02 '13 at 08:34