Assume the following method is properly synchronized and called from a thread A on an object B
After calling this method, when will the thread A become a candidate to get another turn at the CPU?
Can anyone help me realize the above through code and I'm little bit scary at the bold portion above. If I can get an explanation in the form of a code that will really help me understand synchronization concept to its depth. Ranchers, please help me...
it means that thread A is in a synchronized block, that has been synchronized on object b. It enters the waiting room of object b and waits there a) until some other thread notifies one or all waiting threads in the waiting room of object b and so our thread. or b) 2000 milliseconds are over.
Here's an example code. It's a bit long, but shows the two possibilities. In the part above the sleep in the main method a thread doesn't get notified, and in the part below a thread waits, but becomes notified and ends earlier. The sleep in the main method only seperates the two versions. I don't provide the output. Try it to see the timing.
Thanks for the example. Your explanations are really helping me to understand. Particularily, your garbage collection diagram was really understandable and I can now easily tweak out questions related to gc. Hope that after trying out the above code, I will be comfortable with synching threads as well.