serge       01/11/02 19:17:10

  Modified:    src/java/org/apache/james/mailrepository
                        JDBCMailRepository.java
  Log:
  Wrap excalibur's getConnection in a retry block since it doesn't pool well when at 
max num of conns.
  
  Revision  Changes    Path
  1.10      +28 -13    
jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java
  
  Index: JDBCMailRepository.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-james/src/java/org/apache/james/mailrepository/JDBCMailRepository.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JDBCMailRepository.java   2001/11/02 15:19:40     1.9
  +++ JDBCMailRepository.java   2001/11/03 03:17:10     1.10
  @@ -481,12 +481,14 @@
               retrieveMessage.close();
               return mc;
           } catch (SQLException sqle) {
  -            System.err.println("Error retrieving message");
  -            System.err.println(sqle.getMessage());
  -            System.err.println(sqle.getErrorCode());
  -            System.err.println(sqle.getSQLState());
  -            System.err.println(sqle.getNextException());
  -            sqle.printStackTrace();
  +            synchronized (System.err) {
  +                System.err.println("Error retrieving message");
  +                System.err.println(sqle.getMessage());
  +                System.err.println(sqle.getErrorCode());
  +                System.err.println(sqle.getSQLState());
  +                System.err.println(sqle.getNextException());
  +                sqle.printStackTrace();
  +            }
               throw new RuntimeException("Exception while retrieving mail: " + 
sqle.getMessage());
           } catch (Exception me) {
               me.printStackTrace();
  @@ -525,7 +527,6 @@
               } catch (Exception me) {
                   throw new RuntimeException("Exception while removing mail: " + 
me.getMessage());
               } finally {
  -                unlock(key);
                   if (conn != null) {
                       try {
                           conn.close();
  @@ -533,6 +534,7 @@
                           //ignore
                       }
                   }
  +                unlock(key);
               }
           }
       }
  @@ -572,13 +574,26 @@
        * Opens a database connection.
        */
       protected Connection getConnection() {
  -        try {
  -            return datasource.getConnection();
  -        } catch (SQLException sqle) {
  -            sqle.printStackTrace();
  -            throw new CascadingRuntimeException(
  -                "An exception occurred getting a database connection.", sqle);
  +        int attempts = 0;
  +        while (attempts < 1000) {
  +            try {
  +                return datasource.getConnection();
  +            } catch (SQLException e1) {
  +                if (e1.getMessage().equals("Could not create enough Components to 
service your request.")) {
  +                    //stupid pool
  +                    try {
  +                        Thread.sleep(50);
  +                    } catch (InterruptedException ie) {
  +                        //ignore
  +                    }
  +                    attempts++;
  +                } else {
  +                    throw new CascadingRuntimeException(
  +                        "An exception occurred getting a database connection.", e1);
  +                }
  +            }
           }
  +        throw new RuntimeException("Failed to get a connection after " + attempts + 
" attempts");
       }
   
       public boolean equals(Object obj) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to