You should use a simple pooling library such as C3P0 and configure the number of connections according to your requirement. Connection lifecycle management will be handled by the library, and you will be freed from establishing a connection, drop them in inactive periods, restore if necessary, etc.,
source share