src/share/classes/java/awt/event/InvocationEvent.java
Print this page
@@ -26,10 +26,13 @@
package java.awt.event;
import java.awt.ActiveEvent;
import java.awt.AWTEvent;
+import sun.awt.AWTAccessor;
+import sun.awt.AWTInterruptedException;
+
/**
* An event which executes the <code>run()</code> method on a <code>Runnable
* </code> when dispatched by the AWT event dispatcher thread. This class can
* be used as a reference implementation of <code>ActiveEvent</code> rather
* than declaring a new class and defining <code>dispatch()</code>.<p>
@@ -125,10 +128,20 @@
/*
* JDK 1.1 serialVersionUID.
*/
private static final long serialVersionUID = 436056344909459450L;
+ static {
+ AWTAccessor.setInvocationEventAccessor(
+ new AWTAccessor.InvocationEventAccessor() {
+ @Override
+ public void dispose(InvocationEvent ie) {
+ ie.dispose();
+ }
+ });
+ }
+
/**
* Constructs an <code>InvocationEvent</code> with the specified
* source which will execute the runnable's <code>run</code>
* method when dispatched.
* <p>This is a convenience constructor. An invocation of the form
@@ -226,10 +239,23 @@
this.notifier = notifier;
this.catchExceptions = catchThrowables;
this.when = System.currentTimeMillis();
}
+ /*
+ * Marks the event as dispatched and notifies all interested parties.
+ */
+ private void setDispatched() {
+ dispatched = true;
+
+ if (notifier != null) {
+ synchronized (notifier) {
+ notifier.notifyAll();
+ }
+ }
+ }
+
/**
* Executes the Runnable's <code>run()</code> method and notifies the
* notifier (if any) when <code>run()</code> has returned or thrown an exception.
*
* @see #isDispatched
@@ -249,18 +275,20 @@
}
else {
runnable.run();
}
} finally {
- dispatched = true;
-
- if (notifier != null) {
- synchronized (notifier) {
- notifier.notifyAll();
- }
+ setDispatched();
}
}
+
+ private void dispose() {
+ throwable = exception =
+ new AWTInterruptedException(
+ "The event is discarded due to Event Thread interruption");
+
+ setDispatched();
}
/**
* Returns any Exception caught while executing the Runnable's <code>run()
* </code> method.