C
cppaddict
The main event handling method in my EventHandler class looks like
this:
<code>
public synchronized void performAction(Event e) {
System.out.println(((ActionEvent) e).toString() );
mProcessingStrategy.doAction((ActionEvent) e);
}
</code>
The initial processing strategy's doAction() calls a series of other
methods, some of which are methods of EventHandler's members. While
doAction() is executing a loop in one of these member methods, it
seems that another thread is able to execute the synchronized
performAction(), even though the original thead has not yet returned
and is not wait() ing.
How do I know it hasn't returned?
I put a a println() statement in the loop, and also put a print
statement at the top of performAction, as you can see above. Then I
get output like this:
looping...
looping...
looping...
Printing another ActionEvent....
looping....
looping....
Since mProcessingStrategy's initial doAction() method changes
mProcessingStrategy to a new strategy which does not call the above
loop, I know that the first thread is printing the "looping..." lines
both before and after the new ActionEvent is printed. Yet according to
my understanding of synchronized, this should be impossible. Am I
missing something? What could be allowing this to happen?
Thanks,
cpp
this:
<code>
public synchronized void performAction(Event e) {
System.out.println(((ActionEvent) e).toString() );
mProcessingStrategy.doAction((ActionEvent) e);
}
</code>
The initial processing strategy's doAction() calls a series of other
methods, some of which are methods of EventHandler's members. While
doAction() is executing a loop in one of these member methods, it
seems that another thread is able to execute the synchronized
performAction(), even though the original thead has not yet returned
and is not wait() ing.
How do I know it hasn't returned?
I put a a println() statement in the loop, and also put a print
statement at the top of performAction, as you can see above. Then I
get output like this:
looping...
looping...
looping...
Printing another ActionEvent....
looping....
looping....
Since mProcessingStrategy's initial doAction() method changes
mProcessingStrategy to a new strategy which does not call the above
loop, I know that the first thread is printing the "looping..." lines
both before and after the new ActionEvent is printed. Yet according to
my understanding of synchronized, this should be impossible. Am I
missing something? What could be allowing this to happen?
Thanks,
cpp