我一直在使用 Play 2.0.2 来创建 Java 应用程序。这几天我遇到了一个问题。在 ~100 请求之后,服务器开始抛出这个异常:
[[SQLException: 等待空闲可用连接超时。]]
我创建了一个Connection
with的新实例DB.getConnection()
。我不关闭Connection
实例,因为每个请求只有一个实例,据我所知,它会Connection
在活动 TCP 连接关闭时自动关闭实例。我试图增加db.default.connectionTimeout
价值,100 seconds
但它无法解决问题。然后我检查了活动的 Postgresql 连接并且没有活动连接。我也重新启动了 Postgresql,但它也无法解决问题。
目前解决这个问题的唯一方法是杀死 Play20 实例并启动一个新实例。
这是 Play2.0 创建的日志:
! @6cg9il6ki - Internal server error, for request [GET [AN URL]] ->
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[SQLException: Timed out waiting for a free available connection.]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.2]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.2]
at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.2]
at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: java.sql.SQLException: Timed out waiting for a free available connection.
at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:503) ~[bonecp.jar:0.7.1.RELEASE]
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:114) ~[bonecp.jar:0.7.1.RELEASE]
at play.api.db.DBApi$class.getConnection(DB.scala:64) ~[play_2.9.1.jar:2.0.2]
at play.api.db.BoneCPApi.getConnection(DB.scala:273) ~[play_2.9.1.jar:2.0.2]
at play.api.db.DB$$anonfun$getConnection$1.apply(DB.scala:129) ~[play_2.9.1.jar:2.0.2]
at play.api.db.DB$$anonfun$getConnection$1.apply(DB.scala:129) ~[play_2.9.1.jar:2.0.2]