I need to create a custom connection pool in Java in such a way that if a user asks for connection and after using it returns to pool but he can maintain a reference to the connection by assigning it to some variable.
Since he has returned connection to pool I can give that to any other user. Now two users will be having the same connection object which is wrong.
How can I create a connection pool by avoiding such scenario?
This question is asked in an interview. I know there are many libraries are available which provide this functionality but how internally they work to achieve this.