Hi,
I have some code to pull an object out of a pool. The pool is just a vector and it lives in a singleton. I've synchronized both the obtain and release methods. Here is the code:
In my main class I created 500 Threads which all try and get an object, wait a bit and then release it. Since there are only 50 in the pool, I would expect to see the following:
The problem is though that I get the "Obtaining Object" printed out 50 times and then "Couldn't get Object, waiting" another 450 times.
I don't get why this happens as surely only one
Thread can access the getObject at any one time.
Does anyone have any suggestions?
Thanks
Richard