src/share/classes/java/awt/EventQueue.java

Print this page




1022                         }
1023                     }
1024                 );
1025                 AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
1026                 dispatchThread.start();
1027             }
1028         } finally {
1029             pushPopLock.unlock();
1030         }
1031     }
1032 
1033     final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
1034         /*
1035          * This synchronized block is to secure that the event dispatch
1036          * thread won't die in the middle of posting a new event to the
1037          * associated event queue. It is important because we notify
1038          * that the event dispatch thread is busy after posting a new event
1039          * to its queue, so the EventQueue.dispatchThread reference must
1040          * be valid at that point.
1041          */

1042         pushPopLock.lock();
1043         try {
1044             if (edt == dispatchThread) {
1045                 /*
1046                  * Don't detach the thread if any events are pending. Not
1047                  * sure if it's a possible scenario, though.
1048                  *
1049                  * Fix for 4648733. Check both the associated java event
1050                  * queue and the PostEventQueue.
1051                  */
1052                 if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
1053                     return false;
1054                 }
1055                 dispatchThread = null;
1056             }
1057             AWTAutoShutdown.getInstance().notifyThreadFree(edt);
1058             return true;
1059         } finally {
1060             pushPopLock.unlock();
1061         }
1062     }
1063 
1064     /*
1065      * Gets the <code>EventDispatchThread</code> for this
1066      * <code>EventQueue</code>.
1067      * @return the event dispatch thread associated with this event queue
1068      *         or <code>null</code> if this event queue doesn't have a
1069      *         working thread associated with it
1070      * @see    java.awt.EventQueue#initDispatchThread
1071      * @see    java.awt.EventQueue#detachDispatchThread
1072      */




1022                         }
1023                     }
1024                 );
1025                 AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
1026                 dispatchThread.start();
1027             }
1028         } finally {
1029             pushPopLock.unlock();
1030         }
1031     }
1032 
1033     final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
1034         /*
1035          * This synchronized block is to secure that the event dispatch
1036          * thread won't die in the middle of posting a new event to the
1037          * associated event queue. It is important because we notify
1038          * that the event dispatch thread is busy after posting a new event
1039          * to its queue, so the EventQueue.dispatchThread reference must
1040          * be valid at that point.
1041          */
1042         SunToolkit.flushPendingEvents();
1043         pushPopLock.lock();
1044         try {
1045             if (edt == dispatchThread) {
1046                 /*
1047                  * Don't detach the thread if any events are pending. Not
1048                  * sure if it's a possible scenario, though.
1049                  *
1050                  * Fix for 4648733. Check both the associated java event
1051                  * queue and the PostEventQueue.
1052                  */
1053                 if (!forceDetach && (peekEvent() != null)) {
1054                     return false;
1055                 }
1056                 dispatchThread = null;
1057             }
1058             AWTAutoShutdown.getInstance().notifyThreadFree(edt);
1059             return true;
1060         } finally {
1061             pushPopLock.unlock();
1062         }
1063     }
1064 
1065     /*
1066      * Gets the <code>EventDispatchThread</code> for this
1067      * <code>EventQueue</code>.
1068      * @return the event dispatch thread associated with this event queue
1069      *         or <code>null</code> if this event queue doesn't have a
1070      *         working thread associated with it
1071      * @see    java.awt.EventQueue#initDispatchThread
1072      * @see    java.awt.EventQueue#detachDispatchThread
1073      */