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

Print this page




1030                                 new EventDispatchThread(threadGroup,
1031                                                         name,
1032                                                         EventQueue.this);
1033                             t.setContextClassLoader(classLoader);
1034                             t.setPriority(Thread.NORM_PRIORITY + 1);
1035                             t.setDaemon(false);
1036                             return t;
1037                         }
1038                     }
1039                 );
1040                 AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
1041                 dispatchThread.start();
1042             }
1043         } finally {
1044             pushPopLock.unlock();
1045         }
1046     }
1047 
1048     final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
1049         /*




1050          * This synchronized block is to secure that the event dispatch
1051          * thread won't die in the middle of posting a new event to the
1052          * associated event queue. It is important because we notify
1053          * that the event dispatch thread is busy after posting a new event
1054          * to its queue, so the EventQueue.dispatchThread reference must
1055          * be valid at that point.
1056          */
1057         pushPopLock.lock();
1058         try {
1059             if (edt == dispatchThread) {
1060                 /*
1061                  * Don't detach the thread if any events are pending. Not
1062                  * sure if it's a possible scenario, though.
1063                  *
1064                  * Fix for 4648733. Check both the associated java event
1065                  * queue and the PostEventQueue.
1066                  */
1067                 if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
1068                     return false;
1069                 }
1070                 dispatchThread = null;
1071             }
1072             AWTAutoShutdown.getInstance().notifyThreadFree(edt);
1073             return true;
1074         } finally {
1075             pushPopLock.unlock();
1076         }
1077     }
1078 
1079     /*
1080      * Gets the <code>EventDispatchThread</code> for this
1081      * <code>EventQueue</code>.
1082      * @return the event dispatch thread associated with this event queue
1083      *         or <code>null</code> if this event queue doesn't have a
1084      *         working thread associated with it
1085      * @see    java.awt.EventQueue#initDispatchThread
1086      * @see    java.awt.EventQueue#detachDispatchThread
1087      */




1030                                 new EventDispatchThread(threadGroup,
1031                                                         name,
1032                                                         EventQueue.this);
1033                             t.setContextClassLoader(classLoader);
1034                             t.setPriority(Thread.NORM_PRIORITY + 1);
1035                             t.setDaemon(false);
1036                             return t;
1037                         }
1038                     }
1039                 );
1040                 AWTAutoShutdown.getInstance().notifyThreadBusy(dispatchThread);
1041                 dispatchThread.start();
1042             }
1043         } finally {
1044             pushPopLock.unlock();
1045         }
1046     }
1047 
1048     final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
1049         /* 
1050          * Minimize discard possibility for non-posted events
1051          */
1052         SunToolkit.flushPendingEvents();
1053         /*
1054          * This synchronized block is to secure that the event dispatch
1055          * thread won't die in the middle of posting a new event to the
1056          * associated event queue. It is important because we notify
1057          * that the event dispatch thread is busy after posting a new event
1058          * to its queue, so the EventQueue.dispatchThread reference must
1059          * be valid at that point.
1060          */
1061         pushPopLock.lock();
1062         try {
1063             if (edt == dispatchThread) {
1064                 /*
1065                  * Don't detach the thread if any events are pending. Not
1066                  * sure if it's a possible scenario, though.
1067                  *
1068                  * Fix for 4648733. Check both the associated java event
1069                  * queue and the PostEventQueue.
1070                  */
1071                 if (!forceDetach && (peekEvent() != null)) {
1072                     return false;
1073                 }
1074                 dispatchThread = null;
1075             }
1076             AWTAutoShutdown.getInstance().notifyThreadFree(edt);
1077             return true;
1078         } finally {
1079             pushPopLock.unlock();
1080         }
1081     }
1082 
1083     /*
1084      * Gets the <code>EventDispatchThread</code> for this
1085      * <code>EventQueue</code>.
1086      * @return the event dispatch thread associated with this event queue
1087      *         or <code>null</code> if this event queue doesn't have a
1088      *         working thread associated with it
1089      * @see    java.awt.EventQueue#initDispatchThread
1090      * @see    java.awt.EventQueue#detachDispatchThread
1091      */