I want to implement pull. Came to mind to make a map with the connections and to make the counter "open connections". After connection add connection to the pool. When reusing it removed from map (without touching the counter), and as soon as he released it back to return to the map. And Mapa to pull the connection randomly. If available connections are not present that to check how many connections (the value of the counter) and if they are less than the maximum available then create a new one. Otherwise, throw in a turn (if you please then enter a description of the logic queues in the answers)
I don't need code. I want to know I had the right train of thought.
then just add that
the old connection should(can) be removed,
to consider appeals from different threads.
If you reach the limit, you can block the call whether to return fail
Why would a random choice - there is no need.
Additional checks for correctness of the code, the consideration of the dual returns
Ideally, the return could be done in destruere well, or the equivalent in that language, or defer or whatever
Katlynn_Ha answered on July 9th 19 at 10:58
Random to pull too much. If we are talking about database connections - they are identical.
And we must not forget to return to pool - there might be an ambush.