Re: synchronization is not working right between two copies of the
same class for member function
johnkerich@verizon.net wrote:
I think Eric Sosman that you should re-read the post since I thought I
made it clear that I already know that the while loop code the previous
coder wrote did not work and I was trying to get synchronization to
work with the existing class as coded. As for the new Global being
"completely useless" you missed the point that the class reference was
not passed into any of the threads [...]
Doesn't matter. Each thread (according to your original post)
performs "gd = new Global()". It follows that they all have wired-
in knowledge of the name of the Global class, and could use that name
to synchronize explicitly on the Global.class object, or to call
static methods (synchronized or not) of the Global class, or to refer
to static variables of the Global class. There was nothing in your
message to indicate that the actual instances of Global served any
useful purpose.
As for making synchronization work by making the member static,
"synchronized static void", I was thinking that was the way to go over
the weekend, so thanks to Patricia and Eric for confirming that's the
way to fix this problem.
Well, good luck! I still fear this is only the onion's outermost
layer, though.
--
Eric Sosman
esosman@acm-dot-org.invalid