How to force DataSource termination and reload connection pool?

1.2k Views Asked by At

Is it possible to force termination of a tomcat-dbcp connection pool and any open connections? And then reinitialize the pool, reusing the pool configuration?

@Autowired
private org.apache.tomcat.jdbc.pool.DataSource ds;

ds.close(true);
//ds.open(); does not exists. how to reinitialize, without having to reconfigure the pool
1

There are 1 best solutions below

0
On

According the source code of tomcat8-dbcp. After close(true) of org.apache.tomcat.jdbc.pool.DataSourceProxy is invoked, the class variable pool will reset to null. But a new object will be created using the same configuration once other methods access the pool variable. So you don't have to reinitialize the DataSource.