VB_
VB_

Reputation: 45702

Concurrency: implement connection timeout in custom connection pool

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

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

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

user2463094
user2463094

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

Related Questions