[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] fix modal dialog 100% CPU usage
From: |
Thomas Fitzsimmons |
Subject: |
[cp-patches] fix modal dialog 100% CPU usage |
Date: |
Tue, 23 Aug 2005 01:42:19 -0400 |
Hi,
Within EventQueue.getNextEvent we were checking isDispatchThread before
waiting for more events to be posted. This was a residual bit of code
from the single-thread model, but it didn't belong anymore, and was
causing 100% CPU usage when a Dialog was closed.
If the dialog event dispatch thread called getNextEvent while or after
the dialog event queue was popped from the dialog stack, then
isDispatchThread would return false. This had a disastrous effect, as
it would leave the dispatch thread running an empty while loop:
while (next_in == next_out)
{
if (isDispatchThread())
{
// We are not allowed to return null from this method, yet
it
// is possible that we actually have run out of native
events
// in the enclosing while() loop, and none of the native
events
// happened to cause AWT events. We therefore ought to check
// the isShutdown() condition here, before risking a "native
// wait". If we check it before entering this function we
may
// wait forever for events after the shutdown condition has
// arisen.
if (isShutdown())
throw new InterruptedException();
wait();
}
}
This patch removes the isDispatchThread check. I committed it to
mainline.
Tom
2005-08-23 Thomas Fitzsimmons <address@hidden>
* java/awt/EventQueue.java (getNextEvent): Don't check if this is
the dispatch thread.
Index: java/awt/EventQueue.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/EventQueue.java,v
retrieving revision 1.24
diff -u -r1.24 EventQueue.java
--- java/awt/EventQueue.java 15 Aug 2005 18:32:38 -0000 1.24
+++ java/awt/EventQueue.java 23 Aug 2005 05:25:29 -0000
@@ -76,7 +76,7 @@
private EventDispatchThread dispatchThread = new EventDispatchThread(this);
private boolean shutdown = false;
- synchronized void setShutdown (boolean b)
+ synchronized private void setShutdown (boolean b)
{
shutdown = b;
}
@@ -125,22 +125,19 @@
while (next_in == next_out)
{
- if (isDispatchThread())
- {
- // We are not allowed to return null from this method, yet it
- // is possible that we actually have run out of native events
- // in the enclosing while() loop, and none of the native events
- // happened to cause AWT events. We therefore ought to check
- // the isShutdown() condition here, before risking a "native
- // wait". If we check it before entering this function we may
- // wait forever for events after the shutdown condition has
- // arisen.
+ // We are not allowed to return null from this method, yet it
+ // is possible that we actually have run out of native events
+ // in the enclosing while() loop, and none of the native events
+ // happened to cause AWT events. We therefore ought to check
+ // the isShutdown() condition here, before risking a "native
+ // wait". If we check it before entering this function we may
+ // wait forever for events after the shutdown condition has
+ // arisen.
- if (isShutdown())
- throw new InterruptedException();
+ if (isShutdown())
+ throw new InterruptedException();
- wait();
- }
+ wait();
}
AWTEvent res = queue[next_out];
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] fix modal dialog 100% CPU usage,
Thomas Fitzsimmons <=