You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2006/12/22 12:38:03 UTC

svn commit: r489628 - /xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java

Author: deweese
Date: Fri Dec 22 03:38:02 2006
New Revision: 489628

URL: http://svn.apache.org/viewvc?view=rev&rev=489628
Log:
MemoryMonitor no longer manipulates it's componoents outside of the AWTEventQueue (thank Mark Thomas)

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java?view=diff&rev=489628&r1=489627&r2=489628
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/MemoryMonitor.java Fri Dec 22 03:38:02 2006
@@ -23,6 +23,7 @@
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.EventQueue;
 import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.Graphics;
@@ -676,6 +677,11 @@
         protected boolean suspended;
 
         /**
+         * Runnable for updating components.
+         */
+        protected UpdateRunnable updateRunnable;
+
+        /**
          * Creates a new Thread.
          * @param timeout    The time between two repaint in ms.
          * @param components The components to repaint.
@@ -683,6 +689,7 @@
         public RepaintThread(long timeout, List components) {
             this.timeout = timeout;
             this.components = components;
+            this.updateRunnable = createUpdateRunnable();
             setPriority(Thread.MIN_PRIORITY);
         }
 
@@ -691,15 +698,12 @@
          */
         public void run() {
             for (;;) {
-                long free  = runtime.freeMemory();
-                long total = runtime.totalMemory();
-                Iterator it = components.iterator();
-                while (it.hasNext()) {
-                    Component c = (Component)it.next();
-                    ((MemoryChangeListener)c).memoryStateChanged(total, free);
-                    c.repaint();
-                }
                 try {
+                    synchronized (updateRunnable) { 
+                        if (!updateRunnable.inEventQueue)
+                            EventQueue.invokeLater(updateRunnable);
+                        updateRunnable.inEventQueue = true; 
+                    }
                     sleep(timeout);
                     synchronized(this) {
                         while (suspended) {
@@ -707,6 +711,25 @@
                         }
                     }
                 } catch (InterruptedException e) {}
+            }
+        }
+
+        protected UpdateRunnable createUpdateRunnable() {
+            return new UpdateRunnable();
+        }
+
+        protected class UpdateRunnable implements Runnable {
+            public boolean inEventQueue = false;
+            public void run() {
+                long free  = runtime.freeMemory();
+                long total = runtime.totalMemory();
+                Iterator it = components.iterator();
+                while (it.hasNext()) {
+                    Component c = (Component)it.next();
+                    ((MemoryChangeListener)c).memoryStateChanged(total, free);
+                    c.repaint();
+                }
+                synchronized (this) { inEventQueue = false; }
             }
         }