Frage

Nachdem sich mit c3p0 Konstante satt Verriegelungs ich für einen alternativen Verbindungspool für meine Datenbank BoneCP drehen. Ich habe eine Server-Anwendung, dass die Prozesse rund 7.000 Stück pro Minute und Bedürfnisse diese Elemente in unsere MySQL-Datenbank protokollieren. Ich habe zur Zeit 100 Worker-Threads und meinen Pool wie so ein:

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

Sind diese Einstellungen akzeptabel für eine solche App? Ich frage, weil nach einer Minute oder zwei in Lauf ich BoneCP Ausnahmen wurde, wenn ich versuche getConnection auf den Pool zu nennen. Danke für die Hilfe.

Hier ist der Code, den ich in meinem Arbeitsthreads für die db Anrufe verwendet wird, kann es nicht auf der dbConn = this.dbPool.getConnection() Linie scheitern. Bin ich nicht Verbindungen richtig schließen?

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

Das ist der Fehler, den ich sah:

 [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)
War es hilfreich?

Lösung

  

Sind diese Einstellungen akzeptabel für eine solche App? Ich frage, weil nach einer Minute oder zwei in Lauf ich boneCP Ausnahmen wurde, wenn ich versuche getConnection auf den Pool zu nennen. Dank für die Hilfe.

Wenn Sie 100 Mitarbeiter haben, warum beschränken Sie den Pool zu 50 Verbindungen (Anzahl der Partitionen x max Anzahl der Verbindungen pro Partition d 5 x 10 in Ihrem Fall)?

  

Bin ich nicht zu schließen Verbindungen richtig?

sieht ok (aber vielleicht connectionWatch ermöglichen, wie angedeutet, um zu sehen, was die Warnung genau ist). Ich persönlich schließen alle Ressourcen verwenden I, einschließlich der Anweisungs- und Ergebnismengen. Nur für den Fall, hier ist das Idiom ich benutze:

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) {}
}

Sie könnten Gruppe der oben Anrufe in einer statischen Methode einer Utility-Klasse.

Sie können auch eine href verwenden <= "http://commons.apache.org/dbutils/apidocs/org/apache/commons/dbutils/DbUtils.html#closeQuietly(java.sql.Connection,%20java.sql .Statement,% 20java.sql.ResultSet)“rel = "noreferrer"> DbUnit.closeQuietly(Connection, Statement, ResultSet) von Commons DbUtils, die bereits erledigt diese.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top