8130735: javax.swing.TimerQueue: timer fires late when another timer starts
authorssadetsky
Tue, 28 Jul 2015 20:59:26 +0300
changeset 32120 06c83c5f2912
parent 32119 1778956d7bee
child 32121 93ad23865c9e
8130735: javax.swing.TimerQueue: timer fires late when another timer starts Reviewed-by: alexsch, serb, azvegint
jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java	Tue Jul 28 20:55:45 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/swing/TimerQueue.java	Tue Jul 28 20:59:26 2015 +0300
@@ -94,6 +94,9 @@
     void startIfNeeded() {
         if (! running) {
             runningLock.lock();
+            if (running) {
+                return;
+            }
             try {
                 final ThreadGroup threadGroup = AppContext.getAppContext().getThreadGroup();
                 AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
@@ -166,15 +169,17 @@
         try {
             while (running) {
                 try {
-                    Timer timer = queue.take().getTimer();
+                    DelayedTimer runningTimer = queue.take();
+                    Timer timer = runningTimer.getTimer();
                     timer.getLock().lock();
                     try {
                         DelayedTimer delayedTimer = timer.delayedTimer;
-                        if (delayedTimer != null) {
+                        if (delayedTimer == runningTimer) {
                             /*
-                             * Timer is not removed after we get it from
-                             * the queue and before the lock on the timer is
-                             * acquired
+                             * Timer is not removed (delayedTimer != null)
+                             * or not removed and added (runningTimer == delayedTimer)
+                             * after we get it from the queue and before the
+                             * lock on the timer is acquired
                              */
                             timer.post(); // have timer post an event
                             timer.delayedTimer = null;