1 Reply Latest reply on Aug 20, 2010 6:27 AM by Mads Moelgaard Andersen

    Why am I still seeing the HouseKeepingMessage ?

    Mads Moelgaard Andersen Newbie

      Hi

      I keep getting this "HouseKeeping" message for both connections and statements. and I don't understand why.

       

      All my JDBC calls follow the same pattern:

       

      public ArrayList<ObjectScore> getObjectIdsAndScore(long someLong, long anotherLong, long aThirdLong, String aString) throws Exception
          {        
              ArrayList<ObjectScore> result = new ArrayList<ObjectScore>(500000);
              ResultSet rs = null;
              try
              {            
                  Connection conn = getConnection();
                  StringBuffer sql = new StringBuffer();
      
                  *** BUILDING SOME SQL ***          
      
                  rs = executeSelect(conn, sql.toString(), fetchsize);
      
                  
                  rs.beforeFirst();
                  while (rs.next())
                      result.add(new ObjectScore( rs.getLong(1), rs.getFloat(2)));
      
                  result.trimToSize();
              } 
              catch (Exception e)
              {    
                  logger.error("getObjectIdsAndScore failed: "+e.getMessage());
                  throw e;
              }
              finally
              {
                  try
                  {
                      if (rs.getStatement() != null) rs.getStatement().close();
                      
                  }
                  catch (Exception ignored) 
                  {
                      
                  }    
                  
                  try
                  {
                      if (rs != null) rs.close();
                      rs = null;
                  }
                  catch (Exception ignored) 
                  {
                      
                  }        
                  closeConnection(); 
              }
              return result;
          }

      Both getConnection() and closeConnection() are inherited methods.

       

      public ResultSet executeSelect(Connection connection, String sql, int fsize) throws Exception
          {    
              ResultSet rs = null;        
              try
              {        
                  sql = (sql.endsWith(";") ? sql.substring(0, sql
                          .length() - 1) : sql);
                  logger.info("SQL: " + sql);
                  Statement statement = connection.createStatement(
                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                          ResultSet.CONCUR_READ_ONLY);
                  statement.setFetchSize(fsize);
                  rs = statement.executeQuery(sql);
                  
              } 
              catch (Exception e)
              {
                  logger.error("executeSelect failed: "+e.getMessage());
                  throw e;
              }    
              finally
              {
      
              }
              return rs;            
          }   
      

       

      As you can see the first snippet opens and closes the connection. The second creates both the statement and the resultset where the first closes them both. Still I get WARNs like

       

      14:01:47,320 WARN  [WrappedConnection] Closing a result set you left open! Please close it yourself.
      java.lang.Throwable: STACKTRACE
          at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(WrappedStatement.java:744)
          at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:217)
      

       

      Pointing out the method for the first snippet.

       

      I also get following when a MDB exits the onMessage method.

       

      [CachedConnectionManager] Closing a connection for you.  Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@844674
      

       

      I've already read

       

      http://community.jboss.org/wiki/WhatDoesTheMessageDoYourOwnHousekeepingMean

       

      and I guess my code pretty much follow the outlined pattern, so what is wrong?

       

      Best regards

      Mads M Andersen

        • 1. Re: Why am I still seeing the HouseKeepingMessage ?
          Mads Moelgaard Andersen Newbie

          Hi

           

          I've figured it out. After googling and googling and googling on the subject. I finally found a discussion on some forum that pointed me in the right direction. It lead me to organize my code like the following example

           

          The method returns sql based on the sql passed to the database and data in the DB.

              private String getGeneratedSql(String sql) throws Exception
              {
                  logger.debug("Enter getGeneratedSql method.");
                  String result = null;
                  Connection conn = ds.getConnection();        
                  try
                  {
                      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);            
                      try
                      {
                          stmt.setFetchSize(this.mFetchSize);
                          ResultSet rs = stmt.executeQuery(sql);
                          try
                          {
                              if (rs.first()) result = rs.getString(1);
                              else throw new Exception("Could not retrieve generated sql.");
                          }
                          finally
                          {
                              rs.close();
                          }
                      }
                      finally
                      {
                          stmt.close();
                      }
                  }
                  finally
                  {
                      conn.close();
                      logger.debug("Exit getGeneratedSql method.");
                  }
                  
                  return result; 
              }
          

           

          What seems essential to avoid the "HouseKeeping" warning and what I cannot explain is that open/close has to happen within the same scope, i.e same method or compound statement.

           

          Anyway, thanks to the discussion that pushed me in the right direction.

           

          Best regards

          Mads M Andersen