Set the maximum number of seconds a connection can persist when connecting to Cloud SQL for MySQL by using the HikariCP JDBC connection pool library.
For detailed documentation that includes this code sample, see the following:
// maxLifetime is the maximum possible lifetime of a connection in the pool. Connections that // live longer than this many milliseconds will be closed and reestablished between uses. This // value should be several minutes shorter than the database's timeout value to avoid unexpected // terminations. config.setMaxLifetime(1800000); // 30 minutes
To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.