Reputation: 45702
I have to implement my own connection pool, and I want the connection will automatically return to the pool after some CONNECTION_TIMEOUT. How can I achive that?
Everything that comes to mind is to use ScheduledExecutorService in a separate thread and replan it each time the connection is used.
Any other ideas?
Upvotes: 0
Views: 418
Reputation: 136062
If a user of your connection pool borrowed a connection then it's the user responsibility to return it to the pool. The connection cannot return itself to the pool.
Upvotes: 0
Reputation:
You can use the client petition for a pooled connection, for triggering some actions, for example, check the timeout for currently used connections, and realease the currently used connections which timeout has expired. You will avoid using a new thread.
Upvotes: 1