gpt4 book ai didi

java - UCP工作算法

转载 作者:行者123 更新时间:2023-12-02 11:35:53 24 4
gpt4 key购买 nike

我使用 Oracle 的通用连接池。我正在研究这个计划

class Action {
static PoolDataSource initPool() {
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setURL(".........");
pds.setUser("user");
pds.setPassword("pass");
pds.setInitialPoolSize(0);
return pds;
}

static final PoolDataSource pds = initPool();

void doAction() {
Connection connection = pds.getConnection();
..........
connection.close(); // ????
}
}

需要调用connection.close()吗? doAction之后完成还是使用池的整个感觉会丢失,并且那里的连接应该保持打开状态,直到它们自己超时关闭为止?

最佳答案

TL;博士。是的,关闭它们。它实际上并没有关闭,而是返回到连接池以供下一次 getConnection() 调用。

完整的文档在这里: https://docs.oracle.com/cd/E11882_01/java.112/e12265/connect.htm#CHDJCGGB

Borrowed connections that are no longer being used should be returned to the pool so that they can be available for the next connection request. The close method is used to close connections and automatically returns the connections to the pool. The close method does not physically remove the connection from the pool.

Borrowed connections that are not closed will remain borrowed; subsequent requests for a connection result in a new connection being created if no connections are available. This behavior can cause many connections to be created and can affect system performance.

关于java - UCP工作算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com