Originally Posted by
hellokitty25
Hi
I almost got the output. Just that as this is a thread, the numOfballs must be synchronized. Otherwise the numOfball will not be correct.
Again, a variable cannot be synchronized. What probably must be synchronized is the method that sets this variable. Make this variable volatile, and then you will need to use a shared Object that it can synchronize perhaps a static public Object held by a variable called "lock". Whatever you do, do not synchronize on an object of the class that you make 10 instances of.