I have a Play Application running using HikariCP jdbc connection pool.
The application will run fine for a while but after a short period of time it will shut down the connection pool meaning I can no longer use the application.
SBT build:
name := "virtual-betting"
version := "1.0"
lazy val root = (project in file(".")).enablePlugins(PlayJava).settings(javacOptions ++= Seq("-source", "1.8", "-target", "1.8"))
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
javaJdbc,
javaJpa,
javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.1-api"),
"org.hibernate" % "hibernate-core" % "5.1.0.Final",
"org.hibernate" % "hibernate-entitymanager" % "5.1.0.Final",
"com.typesafe.play" % "play-java-jpa_2.11" % "2.5.3",
"org.springframework" % "spring-context" % "4.2.4.RELEASE",
"org.webjars" % "bootstrap" % "3.3.4",
"mysql" % "mysql-connector-java" % "5.1.42",
cache,
javaWs,
"org.jsoup" % "jsoup" % "1.7.2",
"org.apache.commons" % "commons-email" % "1.4",
"org.apache.cxf" % "cxf-rt-rs-client" % "3.1.6",
"com.google.code.gson" % "gson" % "2.7",
"com.squareup.okhttp3" % "okhttp" % "3.4.1"
)
fork in run := false
fork in run := true
application.conf:
## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"
pool = "hikaricp"
# Play uses HikariCP as the default connection pool. You can override
# settings by changing the prototype:
prototype {
pool = "hikaricp"
# Sets a fixed JDBC connection pool size of 50
hikaricp.minimumIdle = 0
hikaricp.maximumPoolSize = 30
hikaricp.connectionTimeout = 30000
hikaricp.idleTimeout = 600000
hikaricp.maxLifetime = 1800000
hikaricp.leakDetectionThreshold = 5000
hikaricp.connectionTestQuery = "SELECT 1"
hikaricp.readOnly = false
hikari.dataSourceClassName = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
# The database url
#url = "jdbc:mysql://localhost:3306/madduxsp_sportsbook?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"
registerMBeans = true
poolName = "sportsbook_pool"
}
}
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost:3306/madduxsp_sportsbook_new?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"
db.default.username=root
db.default.password=mypassword
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
application.secret="mysecret"
spring.context.location=application-context.xml
I've written some code to keep the DB connection alive, that works, in case it is shut down due to inactivity.
My DbKeepAliveService:
package services;
import play.Logger;
import play.db.jpa.JPAApi;
import util.DbKeepAliveTask;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Timer;
@Singleton
public class DbKeepAliveService {
private final JPAApi jpa;
@Inject
public DbKeepAliveService(JPAApi jpa) {
this.jpa = jpa;
DbKeepAliveTask dbKeepAliveTask = new DbKeepAliveTask(jpa);
Logger.info("Application has started");
Timer timer = new Timer("dbKeepAlive", true);
timer.schedule(dbKeepAliveTask, 0, 1200000);
}
}
Except this doesn't work. Here are my logs:
2017-05-06 06:12:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:32:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:52:15,010 [INFO] from application in dbKeepAlive - Keeping database connection alive...
2017-05-06 06:58:35,894 [INFO] from application in Thread-8 - Application shutdown...
2017-05-06 06:58:36,054 [INFO] from application in Thread-8 - Shutting down connection pool.
Does anyone have any ideas why it might keep shutting down the Db Connection pool? I suspect it is something to do with my configuration but I honestly can't be sure.
I also read it could be to do with not running the application in Production mode but I've set the secret.
I run the application using the following command:
./bin/virtual-betting -Dconfig.file=conf/production.conf -Dplay.crypto.secret="mysecret" &
With the play.crypto.secret
property set in the conf/production.conf
file.
Been looking at this for a long time so help is majorly appreciated!