classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nasty problem in javax.swing.Timer.restart()


From: Meskauskas Audrius
Subject: Re: Nasty problem in javax.swing.Timer.restart()
Date: Thu, 10 Nov 2005 19:26:26 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Thanks for idea. The problem seems real and the solution may work. Nice patch, also. I have several suggestions:

1.The Waker.run has two queueLock.wait statements. If the thread is interrupted (notified) at the second waiting statement (inside the loop), the "interrupting" flag in your patch is not reset to false. The application will hang in the endless loop inside the Timer.start().

Probably the flag should be reset to false inside the finally {}, where the "running" is reset to false.

2. The private methods isInterrupting() and setInterrupting() probably need not be synchronized as
they just get/set a single boolean field.

3. You code formatting exactly follows Sun style. This project uses GNU style. Try to reformat like the rest of the
class and also other Classpath classes and also as described in
http://www.gnu.org/software/classpath/docs/hacking.html.

4. Try to document the new methods you introduce.

5. You are not in the project member list. We must register everybody here; contact Mark ( address@hidden <https://savannah.gnu.org/sendmessage.php?touser=301>) to get the form to sign and a couple of cute gnu images. Before that, we cannot apply the patch.

Best regards.

Audrius.
*

Joao Victor wrote:

Yesterday i posted this bug about tooltips appearing too fast:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24763

However, i was taking a look at the ToolTipManager.java source, and
noticed the logic apparently is already there.

So i started investigating the problem, and found something. In a few
words: ToolTipManager uses javax.swing.Timer to schedule the
appearance of the tooltip, as you may know. The problem happens
because when it calls Timer.restart(), restart() starts a new thread
before _really_ stopping the previous one.

It calls:
stop()
start()

However, because of the whole nature of wait/notifys/threads, when
that start() is executed, stop() has only notified the other thread -
it doesn't mean the other thread _really_ stopped.

So, you end up with 2 threads in the 'start' state. One of them will
block at the 'wait()' code, the other just moves on and shows the
tooltip -- too early.

The attached patch i'm sending apparently fixes this problem. I don't
know if it's the best way to fix it, though; take a look at what it
does and see if it's useful.

Cheers,
J.V.
------------------------------------------------------------------------

--- javax/swing/Timer.java      2005-11-10 15:09:08.224949882 +0000
+++ javax/swing/Timer.java-jv   2005-11-10 15:07:12.523395499 +0000
@@ -78,8 +78,10 @@
                  // Ignored
                }

-              if (!running)
+              if (!running) {
+               setInterrupting(false);
                return;
+              }

              queueEvent();

@@ -159,6 +161,7 @@
   * as scheduled. Should only be checked/set with queueLock held.
   */
  boolean running;
+  private boolean interrupting = false;

  /**
   * The delay between subsequent repetetive events.
@@ -379,6 +382,14 @@
    return running;
  }

+  private synchronized void setInterrupting(boolean aStatus) {
+    interrupting = aStatus;
+  }
+
+  private synchronized boolean isInterrupting() {
+    return interrupting;
+  }
+
  /**
   * Add the action listener
   *
@@ -414,6 +425,17 @@
   */
  public void start()
  {
+
+    while (isInterrupting()) {
+       //do nothing
+       try {
+          synchronized (queueLock) {
+                 queueLock.notifyAll();
+         }
+       } catch(Exception e) {
+       }
+    }
+
    synchronized (queueLock)
      {
        if (!running)
@@ -432,6 +454,7 @@
  {
    synchronized (queueLock)
      {
+       setInterrupting(true);
        running = false;
        queue = 0;
        queueLock.notifyAll();
------------------------------------------------------------------------

_______________________________________________
Classpath mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/classpath





reply via email to

[Prev in Thread] Current Thread [Next in Thread]