Google Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: In-Person
A. Keep a maxCount that depends on the underlying implementation of the resource availability such as max allowed connections in an RDBMS.
B. Keep a currentCount that needs to be synchronized across threads when incrementing/decrementing
C. Keep a timeOut in case, connection is not released
D. Keep a Queue for waiting clients in case pool is full, must be synchronized as well for multi-threading
E. High level methods: getConnection, releaseConnection, forceTimeout, Queue operations such as push, pop etc.
This is about creating a Singlenton class that holds a cache of connections so that the connections can be reused when future requests to the database are required.
- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> January 20, 2014When you say that "When the user is done, returns them back to the pool" means that you just freed one of your N connection hold in your cache, wich means It can be use by another user/request/process/thread/etc
There is a creational design pattern called object pool pattern if you want to get into details.
Additionally, there are a lot open source software that are in charged of such task. In real life, It is hard that someones needs to rebuild the wheel, but It is a good idea to knoew in details such open source software to disscuss it during the interview and why not came up with your own implentation.
hope It works.
cheers