1
votes

I am working in Multi Tenant Spring Boot application. I am using the concept of one DB per Tenant approach. I have configured the dynamic database creation and connection. Also those database configurations are stored in a Map. Now I would like to implement an approach to clear DataSource which is idle for long time?

1
hi, please read here -> stackoverflow.com/help/how-to-ask , and then edit your question :) - Leviand
instead of storing database connection details inside Map you can also use another database table which will provide dynamic connectivity based on tenantId and only 1 datasource will be loaded - emotionlessbananas
@emotionlessbananas storing the details at anywhere is fine. But my requirement is how to find the particular datasource is idle for long time? - Alexpandiyan Chokkan
in that case you can look into test-while-idle and validation-query property - emotionlessbananas
Do I have to initialize every datasource like the following answer stackoverflow.com/a/48413427/7458887 - Alexpandiyan Chokkan

1 Answers

1
votes

I assume, you create Datasource and attempt to store them in a map,

whilst you create DS. you can mention

basicDataSource.setMinIdle(multitenantConnectionPoolConfig.getMinIdle());

So the connection pools ensure only active connections exist in the pool after the min Idle time expires.