定时任务导致WebLogic 连接池不断增长的一种原因

基于效率考虑,有时会选择使用Connection Pool高级中的Pinned-To-Thread属性。这个属性可以将连接订在执行线程上,即使调用connection的close方法也不会将其释放回连接池,通常情况下这是没有问题的。

当使用定时任务时,我们需要定时任务能够多线程执行,通常会通过编程方式针对每个任务开启一个线程,由于这些线程不会重复使用,而Pinned-To-Thread属性已经将连接绑定到线程上,所以连接池会不断增长。

 

PinnedToThread属性官方说明:

PinnedToThread is an option that can improve performance by enabling execute threads to keep a pooled database connection even after the application closes the logical connection.

When PinnedToThread is enabled, WebLogic Server pins a database connection from the connection pool to an execution thread the first time an application uses the thread to reserve a connection. When the application finishes using the connection and calls connection.close(), which otherwise returns the connection to the connection pool, WebLogic Server keeps the connection with the execute thread and does not return it to the connection pool. When an application subsequently requests a connection using the same execute thread, WebLogic Server provides the connection already reserved by the thread.

With PinnedToThread, there is no locking contention on the connection pool that occurs when multiple threads attempt to reserve a connection at the same time and there is no contention for threads that attempt to reserve the same connection from a limited number of database connections.

If an application concurrently reserves more than one connection from the connection pool using the same execute thread, WebLogic Server creates additional database connections and pins them to the thread, as well.

MBean Attribute (Does not apply to application modules):
JDBCConnectionPoolParamsBean.PinnedToThread

Changes take effect after you redeploy the module or restart the server.

你可能感兴趣的:(项目问题)