Re: Two more multithreading questions
- From: Patricia Shanahan <pats@xxxxxxx>
- Date: Tue, 30 Jan 2007 13:36:30 GMT
Knute Johnson wrote:
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?
I believe most javax.swing component access is supposed to be done in
the event handling thread anyway. Swing was not designed to be
multithread-safe.
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?
Two threads can be in synchronized blocks at the same time, as long as
they are synchronized on different objects. You don't have to use the
object you are protecting, but all accesses to that object must be
synchronized on the same lock object.
Patricia
.
- Follow-Ups:
- Re: Two more multithreading questions
- From: Knute Johnson
- Re: Two more multithreading questions
- References:
- Two more multithreading questions
- From: Knute Johnson
- Two more multithreading questions
- Prev by Date: Re: java performance tool
- Next by Date: Re: Access to local files with signed applet in Vista/IE7
- Previous by thread: Re: Two more multithreading questions
- Next by thread: Re: Two more multithreading questions
- Index(es):
Relevant Pages
|