【发布时间】:2019-11-06 20:19:44
【问题描述】:
我已将 c3PO 设置如下
hibernate.c3p0.min_size = "20";
hibernate.c3p0.max_size = "30";
hibernate.c3p0.maxConnectionAge = "10";
hibernate.c3p0.timeout = "15";
然后我的代码如下
@Transactional
void m1(){
for(int i = 0; i<10; i++){
fetch(); // fetches db entry
Thread.sleep(20000);
update(); // updates db entries
}
}
在这里,我让线程休眠 20 秒(> maxConnectionAge 和超时)。然后代码成功执行没有关闭任何数据库连接。为什么会这样?
谁能帮我理解
一个事务是否只执行一个线程? 如果是这样,为什么我们没有遇到任何数据库超时问题?
什么所有 C3P0 参数/DB 参数导致 db 连接关闭?。另外,@Transactional 是否对这个问题起作用?
【问题讨论】:
标签: hibernate transactions threadpool c3p0 thread-sleep