JDK-8130736 : javax.swing.TimerQueue: timer fires late when another timer starts
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-07-03
  • Updated: 2015-07-08
  • Resolved: 2015-07-08
Related Reports
Duplicate :  
Description
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 ----------


Comments
Exact duplicate of another report , moved necessary information to JDK-8130735.
08-07-2015