< prev index next >

## src/java.desktop/share/classes/java/awt/SequencedEvent.java

Print this page

     118      * Dispatches the nested event after all previous nested events have been
     119      * dispatched or disposed. If this method is invoked before all previous nested events
     120      * have been dispatched, then this method blocks until such a point is
     121      * reached.
     122      * While waiting disposes nested events to disposed AppContext
     123      *
     124      * NOTE: Locking protocol.  Since dispose() can get EventQueue lock,
     125      * dispatch() shall never call dispose() while holding the lock on the list,
     126      * as EventQueue lock is held during dispatching.  The locks should be acquired
     127      * in the same order.
     128      */
     129     public final void dispatch() {
     130         try {
     131             appContext = AppContext.getAppContext();
     132
     133             if (getFirst() != this) {
     134                 if (EventQueue.isDispatchThread()) {
     135                     if (Thread.currentThread() instanceof EventDispatchThread) {
     136                         EventDispatchThread edt = (EventDispatchThread)
     137                                 Thread.currentThread();
     138                         edt.pumpEvents(SentEvent.ID, new Conditional() {
     139                             public boolean evaluate() {
     140                                 return !SequencedEvent.this.isFirstOrDisposed();
     141                             }
     142                         });
     143                     } else {
     144                         if (fxAppThreadIsDispatchThread) {
     145                             fxCheckSequenceThread.start();
     146                             try {
     147                                 // check if event is dispatched or disposed
     148                                 // but since this user app thread is same as
     149                                 // dispatch thread in fx when run with
     150                                 // javafx.embed.singleThread=true
     151                                 // we do not wait infinitely to avoid deadlock
     152                                 // as dispatch will ultimately be done by this thread
     153                                 fxCheckSequenceThread.join(500);
     154                             } catch (InterruptedException e) {
     155                             }
     156                         }
     157                     }
     158                 } else {
     159                     while(!isFirstOrDisposed()) {
     160                         synchronized (SequencedEvent.class) {
     161                             try {
     162                                 SequencedEvent.class.wait(1000);
     118      * Dispatches the nested event after all previous nested events have been
     119      * dispatched or disposed. If this method is invoked before all previous nested events
     120      * have been dispatched, then this method blocks until such a point is
     121      * reached.
     122      * While waiting disposes nested events to disposed AppContext
     123      *
     124      * NOTE: Locking protocol.  Since dispose() can get EventQueue lock,
     125      * dispatch() shall never call dispose() while holding the lock on the list,
     126      * as EventQueue lock is held during dispatching.  The locks should be acquired
     127      * in the same order.
     128      */
     129     public final void dispatch() {
     130         try {
     131             appContext = AppContext.getAppContext();
     132
     133             if (getFirst() != this) {
     134                 if (EventQueue.isDispatchThread()) {
     135                     if (Thread.currentThread() instanceof EventDispatchThread) {
     136                         EventDispatchThread edt = (EventDispatchThread)
     137                                 Thread.currentThread();
     138                         edt.pumpEvents(() -> !SequencedEvent.this.isFirstOrDisposed());

     139                     } else {
     140                         if (fxAppThreadIsDispatchThread) {
     141                             fxCheckSequenceThread.start();
     142                             try {
     143                                 // check if event is dispatched or disposed
     144                                 // but since this user app thread is same as
     145                                 // dispatch thread in fx when run with
     146                                 // javafx.embed.singleThread=true
     147                                 // we do not wait infinitely to avoid deadlock
     148                                 // as dispatch will ultimately be done by this thread
     149                                 fxCheckSequenceThread.join(500);
     150                             } catch (InterruptedException e) {
     151                             }
     152                         }
     153                     }
     154                 } else {
     155                     while(!isFirstOrDisposed()) {
     156                         synchronized (SequencedEvent.class) {
     157                             try {
     158                                 SequencedEvent.class.wait(1000);

< prev index next >