After Full GC yet the instances of socket keep growing?

130 views Asked by At

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);
        }
       }
      }
1

There are 1 answers

5
Robin Green On

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.