-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5
-
Not verified
Name: mgC56079 Date: 04/24/98
Javadoc says:
/**
* Stop dispatching events using this EventQueue instance.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Any pending events are transferred to the previous
* EventQueue for processing by it. If called from the
* initial EventQueue for this AWTContext, an
* EmptyStackException is thrown.
*/
protected synchronized void pop() throws EmptyStackException {
synchronized (prev) {
prev.queue = queue; // may be null
prev.next = null;
prev = null;
next = null;
}
}
However this method neither stops dispatching thread nor sets this.queue to null.
This means that the queue will continue to dispatch pending events.
--- Here is a test ---
import java.util.EmptyStackException;
import java.awt.*;
public class EventQueueTest2 {
public static void main(String[] args) {
PublicEventQueue q1=new PublicEventQueue();
PublicEventQueue q2=new PublicEventQueue();
LockDispatchThreadEvent locker1=new LockDispatchThreadEvent();
LockDispatchThreadEvent locker2=new LockDispatchThreadEvent();
// stop q1's dispatch thread.
q1.postEvent(locker1);
// disable q2's dispatch thread.
q2.postEvent(locker2);
// wait until both threads are locked
while (! (locker1.isDispatched() && locker2.isDispatched())) {
Thread.yield();
}
q1.push(q2);
// this event will not be dispatched by q1 (dispatch thread is locked)
q2.postEvent(new SomeEvent());
// SomeEvent will be dispatched with q1 now. q2 should stop dispatching.
// However q1 is locked so this event should never be dispatched.
q2.pop();
// unlock q2
locker2.setLocked(false);
}
}
class LockDispatchThreadEvent extends AWTEvent implements ActiveEvent {
public LockDispatchThreadEvent() {
super("",0);
}
boolean dispatched=false;
boolean locked=true;
public synchronized boolean isDispatched() {
return dispatched;
}
public synchronized void setLocked(boolean locked) {
this.locked=locked;
notify();
}
public synchronized void dispatch() {
dispatched=true;
// this will disable dispatch thread
while (locked) {
System.out.println("Dispatch thread stopped: "+Thread.currentThread());
try {
wait();
}
catch (InterruptedException e) {
}
}
System.out.println("Dispatch thread resumed: "+Thread.currentThread());
}
}
class SomeEvent extends AWTEvent implements ActiveEvent {
public SomeEvent() {
super("",0);
}
public void dispatch() {
System.out.println("Test failed: SomeEvent dispatched by "+Thread.currentThread());
}
}
class PublicEventQueue extends EventQueue {
public void pop() {
super.pop();
}
}
--- Sample run ---
% java EventQueueTest2
Dispatch thread stopped: Thread[AWT-EventQueue-0,5,main]
Dispatch thread stopped: Thread[AWT-EventQueue-1,5,main]
Dispatch thread resumed: Thread[AWT-EventQueue-1,5,main]
Test failed: SomeEvent dispatched by Thread[AWT-EventQueue-1,5,main]
======================================================================
- relates to
-
JDK-4132303 EventQueue.push() does not clear this.queue
-
- Closed
-