Question

Après en avoir marre avec verrouillage de la constante de c3p0 Je me tourne vers BoneCP pour un pool de connexion alternative pour ma base de données. J'ai une application serveur qui traite environ 7000 points par minute et les besoins de se connecter ces éléments dans notre base de données MySQL. J'ai actuellement 100 threads de travail et ont mis en place ma piscine comme tel:

BoneCPConfig config = new BoneCPConfig();
      config.setJdbcUrl("jdbc:mysql://"+Settings.MYSQL_HOSTNAME+"/"+Settings.MYSQL_DATABASE+"?autoReconnectForPools=true" ); 
      config.setUsername(Settings.MYSQL_USERNAME); 
      config.setPassword(Settings.MYSQL_PASSWORD);
      config.setMinConnectionsPerPartition(5);
      config.setMaxConnectionsPerPartition(10);
      config.setPartitionCount(5);
      config.setAcquireIncrement(5);
      connectionPool = new BoneCP(config); // setup the connection pool

sont les paramètres acceptables pour une telle application? Je demande parce que, après une minute ou deux en cours d'exécution, je recevais des exceptions BoneCP lorsque vous essayez d'appeler getConnection sur la piscine. Merci pour l'aide.

Voici le code que j'utilisais pour les appels db dans mes threads de travail, il ne peut pas échouer sur la ligne de dbConn = this.dbPool.getConnection(). Suis-je pas les connexions fermer correctement?

private void insertIntoDb() {
    try {  
        Connection dbConn = this.dbPool.getConnection();

        try {
            PreparedStatement ps3 = dbConn.prepareStatement("INSERT IGNORE INTO test_table1 SET test1=?, test2=?, test3=?");
            ps3.setString(1, "some string");
            ps3.setString(2, "some other string");
            ps3.setString(3, "more strings");
            ps3.execute();
            ps3.close();

            PreparedStatement ps4 = dbConn.prepareStatement("INSERT IGNORE INTO test_table2 SET test1=?, test2=?, test3=?");
            ps4.setString(1, "some string");
            ps4.setString(2, "some other string");
            ps4.setString(3, "more strings");
            ps4.execute();
            ps4.close();

        } catch(SQLException e) {
            logger.error(e.getMessage());
        } finally {
            try {
                dbConn.close();
            } catch (SQLException e) {
                logger.error(e.getMessage());
            }
        }
    } catch(SQLException e) {
        logger.error(e.getMessage());
    }
}

Ceci est l'erreur que je vois:

 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.
 [java]  WARN [com.google.common.base.internal.Finalizer] (ConnectionPartition.java:141) - BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance.

ERROR pool-2-thread-39 2010-09-04 13:36:19,798 com.test.testpackage.MyTask - null
java.sql.SQLException
    at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:381)
Était-ce utile?

La solution

  

sont les paramètres acceptables pour une telle application? Je demande parce que, après une minute ou deux en cours d'exécution, je recevais des exceptions boneCP en essayant d'appeler getConnection sur la piscine. merci pour l'aide.

Si vous avez 100 travailleurs, pourquoi limiter-vous la piscine à 50 connexions (nombre de partitions x nombre maximum de connexions par partition à savoir 5 x 10 dans votre cas)?

  

Suis-je pas les connexions fermer correctement?

semble correct (mais peut-être permettre connectionWatch comme le laisse entendre de voir ce que l'avertissement est sur le point exactement). Personnellement, je ferme toutes les ressources que j'utilise, y compris les jeux d'instructions et de résultats. Juste au cas où, voici l'utilisation de langage I:

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try {
    conn = pool.getConnection();
    pstmt = conn.prepareStatement(SOME_SQL);
    pstmt.setFoo(1, foo);
    ...
    rs = pstmt.executeQuery();
    ...
} finally {
    if (rs != null) try { rs.close(); } catch (SQLException quiet) {}
    if (pstmt != null) try { pstmt.close(); } catch (SQLException quiet) {}
    if (conn != null) try { conn.close(); } catch (SQLException quiet) {}
}

Vous groupe pourrait les appels ci-dessus dans une méthode statique d'une classe utilitaire.

Ou vous pouvez utiliser DbUnit.closeQuietly(Connection, Statement, ResultSet) de la Chambre des communes dbUtils qui fait déjà.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top