changeset 8450:bd54b89d6812

8130735: javax.swing.TimerQueue: timer fires late when another timer starts Reviewed-by: ssadetsky, alexsch
author alitvinov
date Wed, 03 Feb 2016 18:52:45 +0300
parents 8c76f574aa4f
children 52a661519964
files src/share/classes/javax/swing/TimerQueue.java
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/TimerQueue.java	Wed Jul 13 14:31:09 2016 +0100
+++ b/src/share/classes/javax/swing/TimerQueue.java	Wed Feb 03 18:52:45 2016 +0300
@@ -93,6 +93,9 @@
     void startIfNeeded() {
         if (! running) {
             runningLock.lock();
+            if (running) {
+                return;
+            }
             try {
                 final ThreadGroup threadGroup =
                     AppContext.getAppContext().getThreadGroup();
@@ -168,15 +171,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;