K
Knute Johnson
I've got two specific scenarios I want to ask about:
1) I have a class with an instance variable that is a reference to a
JDialog. In one thread I create new instances of JDialog and make them
visible. They might get closed in this thread as well. In another
thread I close the JDialog using the class instance variable. To ensure
that my dialog closing thread always has a reference to the current
dialog I created the instance variable with volatile. Is this adequate
to guarantee that my closing thread always has a reference to the latest
dialog?
2) If I want to access/modify an Object in two threads, can I use a
reference to any Object in the synchronize statement to do that? It
doesn't have to be the reference to the Object that I am trying to
protect as long as the accesses are all in synchronized blocks?
Thanks very much,
1) I have a class with an instance variable that is a reference to a
JDialog. In one thread I create new instances of JDialog and make them
visible. They might get closed in this thread as well. In another
thread I close the JDialog using the class instance variable. To ensure
that my dialog closing thread always has a reference to the current
dialog I created the instance variable with volatile. Is this adequate
to guarantee that my closing thread always has a reference to the latest
dialog?
2) If I want to access/modify an Object in two threads, can I use a
reference to any Object in the synchronize statement to do that? It
doesn't have to be the reference to the Object that I am trying to
protect as long as the accesses are all in synchronized blocks?
Thanks very much,