Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4239522

Timer seems to stop when the computer sytemdate is turned back

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: krT82822 Date: 05/19/99


      When a java application is running holding a timer and an user
      turns back the computer systemdate, the timer is only throwing
      an event at the moment the original systemdate + delay is
      reached.

      5/19/99 kevin.ryan@eng -- received test case from user:

      /*
      Excuses for my late response on your request for a test case, but hereby
      you receive a simple program that with some beter handwork will
      demonstrate the problem.

      The program shows the systemdate/time in a frame, every 1000
      milliseconds later it will adjust the shown systemdate/time. If you turn
      the systemclock (while the program still runs) forwards nothing shocking
      happens, but when you turn the systemclock backwards the shown
      systemdate/time will stop for as long as the systemclock reaches the
      point it was turned back.

      Hope this will demonstrate the problem properly for you.

      Best Regards, Karel Mentink
      */

      package nl.virgil.personal.karmen.timertest;

      import java.util.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.text.*;

      /**
       * Shows a window with the PC System Date to demonstrate the Timer
       * class behaviour.
       *
       * @version 1.00 19 May 1999
       * @author Dennis Brouwer
       */
      public class TimerTest {

      // To demonstrate the bug found adjust the System Date or Time
      // FORWARD and BACKWARD. If you adjust Date or Time backwards, the
      // timer is completely lost. This is possibly dangerous in certain
      // applications. Please try for yourself.

              public static void main(String[] args) {

                      // Creates a window to show PC System Date.
                      JFrame timerFrame = new JFrame();

                      // Sets the title and size of the window.
                      timerFrame.setTitle("TimerTest");
                      timerFrame.setSize(400,80);
                      timerFrame.setResizable(false);

                      timerFrame.addWindowListener(new WindowAdapter() {
                              public void windowClosing(WindowEvent e) {
                                      System.exit(0);
                              }
                      });

                      // Shows the window on the screen.
                      timerFrame.show();

                      // Creates the pane containing the PC System Date.
                      JPanel labelPane = new JPanel(new GridLayout(2,1));

                      // Creates the label for the PC System Date.
                      systemDateLabel = new JLabel("", SwingConstants.CENTER);
                      systemDateLabel.setForeground(Color.black);

                      // Creates the label for a text line to "play" with the System
                      // Date.
                      JLabel actionLabel = new JLabel("Please change PC System Date/Time forwards AND backwards", SwingConstants.CENTER);
                      actionLabel.setForeground(Color.black);

                      // Adds both labels to the window.
                      labelPane.add(systemDateLabel);
                      labelPane.add(actionLabel);

                      // Add the pane to the window.
                      Container contentPane = timerFrame.getContentPane();
                      contentPane.add(labelPane);

                      // Creates a timer event with one second interval to show the
                      // PC System Date.
                      Timer testTimer = new Timer(1000, new ActionListener() {
                              public void actionPerformed(ActionEvent e) {
                                      // Gets system time and show in decent format.
                                      actualDate = Calendar.getInstance();
                                      systemDateLabel.setText(formatSystemDate());
                              }
                      });

                      // Start the timer.
                      testTimer.start();
              }

              /**
               * Formats the System Date in a readable way.
               */
              private static String formatSystemDate() {
                      // Creates the format for the system date.
                      SimpleDateFormat formattedDate = new SimpleDateFormat ("dd MMMM yyyy hh:mm:ss");

                      // Sets the system date in created format.
                      String format = formattedDate.format(actualDate.getTime());

                      return format;
              }

              private static JLabel systemDateLabel;
              private static Calendar actualDate;
      (Review ID: 57846)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: