-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8u45
-
x86_64
-
windows_7
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The bug which was reported by Review ID:JI-9021974
contains the WRONG SOURCE CODE.
Here is the correct one
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TimerQueueBug {
public static void main(String[] args) throws Exception{
for (int i = 0; i < 80; i++) {
startShortTimer();
}
final boolean[] longDelay = new boolean[1];
final Timer dyn = new Timer(100, null);
dyn.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
try {
if ( longDelay[0] ) {
dyn.setDelay(50);
dyn.start();
} else {
dyn.setDelay(500);
for ( int i = 0; i < 100; i++ ) {
dyn.start();
}
}
longDelay[0] = !longDelay[0];
} catch ( Throwable ex ) {
ex.printStackTrace();
System.exit(99);
}
}
} );
dyn.setRepeats(true);
dyn.start();
while (true) {
Thread.sleep(1);
}
}
private static void startShortTimer() {
final int delay = 100;
Timer t = new Timer( delay, new ActionListener() {
long nextActionExpectedAt;
@Override
public void actionPerformed( ActionEvent e ) {
if (nextActionExpectedAt != 0) {
final long diff = System.currentTimeMillis() - nextActionExpectedAt;
if (diff > 400) {
System.out.println("Delay abnormal: " + diff);
System.exit(1);
}
}
nextActionExpectedAt = System.currentTimeMillis() + delay;
}
} );
t.setRepeats(true);
t.start();
}
}
---------- END SOURCE ----------
A DESCRIPTION OF THE PROBLEM :
The bug which was reported by Review ID:
contains the WRONG SOURCE CODE.
Here is the correct one
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TimerQueueBug {
public static void main(String[] args) throws Exception{
for (int i = 0; i < 80; i++) {
startShortTimer();
}
final boolean[] longDelay = new boolean[1];
final Timer dyn = new Timer(100, null);
dyn.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
try {
if ( longDelay[0] ) {
dyn.setDelay(50);
dyn.start();
} else {
dyn.setDelay(500);
for ( int i = 0; i < 100; i++ ) {
dyn.start();
}
}
longDelay[0] = !longDelay[0];
} catch ( Throwable ex ) {
ex.printStackTrace();
System.exit(99);
}
}
} );
dyn.setRepeats(true);
dyn.start();
while (true) {
Thread.sleep(1);
}
}
private static void startShortTimer() {
final int delay = 100;
Timer t = new Timer( delay, new ActionListener() {
long nextActionExpectedAt;
@Override
public void actionPerformed( ActionEvent e ) {
if (nextActionExpectedAt != 0) {
final long diff = System.currentTimeMillis() - nextActionExpectedAt;
if (diff > 400) {
System.out.println("Delay abnormal: " + diff);
System.exit(1);
}
}
nextActionExpectedAt = System.currentTimeMillis() + delay;
}
} );
t.setRepeats(true);
t.start();
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8130735 javax.swing.TimerQueue: timer fires late when another timer starts
- Resolved