The program has been in use in production suddenly thrown "Connection has already been closed."

1, causes:
the most simple code, no framework, because it involves matters, made a long connection Connection, this connection is passed down until the end of the transaction; otherwise, the rollback. . . There is a transaction process: To re-check the file itself, the file itself has 50,000 data takes about 3 to 5 minutes. After the end of the file itself re-check, re-check the database ,,, re-check the database error abnormal

Connection the getConnection static public () {
    the try {
        // the DataSource
        the Context the InitialContext new new CTX = ();
        CTX = (the Context) ctx.lookup ( "Java: CoMP / the env");
        the javax.sql.DataSource = DS (the javax.sql. dataSource) ctx.lookup ( "data source name"); // the name the JNDI
        connection ds.getConnection Conn = ();
        IF (Conn == null) {
            logger.info ( "empty database connection ------- ----- ");
        } the else {
            logger.info (" not empty database connection ----------- ");
        }
        return Conn;
 
    } the catch (Exception EX) {
        logger.info ( "Get data source of the abnormal ..", EX);
        ex.printStackTrace ();
        return null;
    }
}
2, re-check the database error exception:
the catch (SQLException E) {
    logger.error ( "Database Searching in abnormal!" + E);
    logger.error ( "Database Searching in abnormal!" + E.getMessage ());
    return - 2;
}
 
error log:
java.sql.SQLException: Closed Connection has already been.
. 3, find out the reasons:
① database

There database timeout parameters. After get a connection 3 to 5 minutes without performing a database operation, the database is considered inactive, the resources may be released.

Timeout parameter (did not understand what) is set too 0, this function is disabled, that is never time out.

② server

Program placed on Weblogic server, the server also has a timeout parameter settings.

Inactive Connection Timeout (Inactive Connection Timeout :): set too 0, this function is disabled, that is never time out.

By understanding, Weblogic arranged two data sources, data source wherein a parameter set to 60s. . . During sum test, which can find a pool for the time being released weblogic log in the background.

 

 Visible, the server considers the connection is inactive, the automatic release of the database connection (also explains not find the database connection exception is closed).

 Modifying Inactive Connection Timeout: the 600 (10 minutes), the normal procedure is supported.

 

③ program bug
----------------
Disclaimer: This article is CSDN blogger original article "37358143", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_37358143/article/details/94597129

Released three original articles · won praise 0 · Views 5296

Guess you like

Origin blog.csdn.net/cjlcc/article/details/104067749