mariadb池连接20分钟后自动关闭?

时间:2018-12-02 09:18:38

标签: java mysql mariadb

我正在将mariadb-connectorhikari配合使用,以连接到mysql数据库。

在某个时候,我需要发送一个LOAD DATA语句,因此按如下所示展开连接:

public static Connection prepareConnection(DataSource ds) throws SQLException {
    java.sql.Connection con = DataSourceUtils.getConnection(ds);
    con.setAutoCommit(false);
    con.setAllowLoadLocalInfile(true);

    Statement st = (Statement) con.createStatement();
    st.executeQuery("SET unique_checks = 0");
    st.executeQuery("SET foreign_key_checks = 0");
    st.executeBatch();
    JdbcUtils.closeStatement(st);

    return con;
}

//preparing the LOAD DATA INFILE
MariaDbStatement loaddata = null;
if (ps.isWrapperFor(MariaDbStatement.class)) {
    loaddata = ps.unwrap(MariaDbStatement.class);
    loaddata.setLocalInfileInputStream(new ByteArrayInputStream(item.getBytes()));
}

Connection con = prepareConnection(ds);
//then using the con directly to send the loaddata statement

问题:我正在导入一个相当大的文件,收集语句并批量手动提交。总是在大约20分钟之后Connection(我在整个导入过程中都重复使用)已经关闭。这可能是因为我直接使用了连接,而hikari/mariadb连接池可能已经解决了这个问题?

问题:可能是哪个池参数引起的?

2018-11-29 22:33:34.417  WARN 2200 --- [pool-3-thread-1] com.zaxxer.hikari.pool.ProxyConnection   : HikariPool-1 - Connection org.mariadb.jdbc.MariaDbConnection                                    @599e4925 marked as broken because of SQLSTATE(08000), ErrorCode(1220)

java.sql.SQLNonTransientConnectionException: (conn=1570) Connection is closed
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:234) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:165) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:238) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:356) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.MariaDbStatement.execute(MariaDbStatement.java:407) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.MariaDbConnection.rollback(MariaDbConnection.java:76) ~[mariadb-java-client-2.3.0.jar!/:na]
        at com.zaxxer.hikari.pool.ProxyConnection.rollback(ProxyConnection.java:370) ~[HikariCP-3.2.0.jar!/:na]
        at com.zaxxer.hikari.pool.HikariProxyConnection.rollback(HikariProxyConnection.java) ~[HikariCP-3.2.0.jar!/:na]

Caused by: java.sql.SQLException: Connection is closed
        at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.cmdPrologue(AbstractQueryProtocol.java:1801) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:212) ~[mariadb-java-client-2.3.0.jar!/:na]
        at org.mariadb.jdbc.MariaDbStatement.executeInternal(MariaDbStatement.java:350) ~[mariadb-java-client-2.3.0.jar!/:na]
        ... 12 common frames omitted

旁注:在使用mysql-connector之前,没有没有这个问题。同样具有相同的hikari池设置。因此,我假设必须有一些mariadb-connector设置可能会迫使基础连接关闭?

0 个答案:

没有答案