8130735: javax.swing.TimerQueue: timer fires late when another timer starts
Reviewed-by: alexsch, serb, azvegint
--- 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;