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

java.util.Date(int,int,int,int,int,int) is unable to give hour information

    XMLWordPrintable

Details

    • 10
    • generic
    • solaris_7
    • Verified

    Description


      Java 1.3.1_08 deprecated java.util.Date(int,int,int,int,int,int) is unable
      to give hour information after many many iterations. It gives "0" instead.
      This happens both on single- and multi-processor maschines.
      This happens both on Sparc Solaris 7, 8, 9 and Windows (W2K) platforms.
      This happens both with "-client" and "-server".


      The problem is reproducible, however requires some runtime hours, until it
      shows.


      1. Testcase
      -----------
      % more SimpleJavaUtilDateTest1.java
      /*
       * Created on 03.07.2003
       *
       * To change the template for this generated file go to
       * Window>Preferences>Java>Code Generation>Code and Comments
       */

      import java.sql.Timestamp;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.Date;
      import java.util.GregorianCalendar;

      /**
       * @author s3876
       *
       * To change the template for this generated type comment go to
       * Window>Preferences>Java>Code Generation>Code and Comments
       */

      public class SimpleJavaUtilDateTest1 implements Runnable {
        private static SimpleDateFormat sdfhour = new SimpleDateFormat("HH");
        private int threadCnt = -1;

        private SimpleJavaUtilDateTest1(int idx) {
          this.threadCnt = idx;
        }

        public void run() {
          long cnt = 0;
          while(true) {
              cnt++;
              int hour = (int) (cnt % 5 + 1);
              Date date = new Date(103, 05, 30, hour, 15, 10);
              String strhour = null;
              synchronized (sdfhour) {
                      strhour = sdfhour.format(date);
              }
              if (Integer.parseInt(strhour) != hour) {
                incNok();
                System.out.println(new Date() + " nokcnt = " + nok + " thread-no=" + this.threadCnt + " soll=" + hour + " ist="
      + strhour);
                if (this.nok >= 1000) {
                  System.out.println("nokcnt = " + this.nok + " ==> aborted");
                  System.exit(-1);
                }
              } else {
                resetNok();
                if (cnt % 10000 == 0) {
                      cnt = 0;
                      System.out.println("treadCnt=" + threadCnt + " ok");
                }
              }
          }
        }

        private static long nok = 0;
        private static synchronized void incNok() {
              nok++;
        }
        private static synchronized void resetNok() {
              nok = 0;
        }

        public static void main(String[] args) {
              System.out.println(new Date());
              for (int i = 0; i < 100; i++) {
                SimpleJavaUtilDateTest1 sct = new SimpleJavaUtilDateTest1(i);
                new Thread(sct).start();
              }
        }
      }


      2. Compile:
      -----------
      % /j2sdk1_3_1_08/bin/java -version
      java version "1.3.1_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_08-b03)
      Java HotSpot(TM) Client VM (build 1.3.1_08-b03, mixed mode)
      % /j2sdk1_3_1_08/bin/javac SimpleJavaUtilDateTest1.java
      Note: SimpleJavaUtilDateTest1.java uses or overrides a deprecated API.
      Note: Recompile with -deprecation for details.
      %
      % /j2sdk1_3_1_08/bin/javac -deprecation SimpleJavaUtilDateTest1.java
      SimpleJavaUtilDateTest1.java:34: warning: Date(int,int,int,int,int,int) in java.util.Date has been deprecated
              Date date = new Date(103, 05, 30, hour, 15, 10);
                          ^
      1 warning
      %


      3. Run
      ------

      % /j2sdk1_3_1_08/bin/java -version
      java version "1.3.1_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_08-b03)
      Java HotSpot(TM) Client VM (build 1.3.1_08-b03, mixed mode)
      % /j2sdk1_3_1_08/bin/java SimpleJavaUtilDateTest1
      Mon Jul 07 15:39:25 CEST 2003
      [ takes some seconds until first output appears ]
      treadCnt=38 ok
      treadCnt=25 ok
      treadCnt=72 ok
      treadCnt=6 ok
      treadCnt=16 ok
      treadCnt=45 ok
      treadCnt=17 ok
      treadCnt=67 ok
      treadCnt=82 ok
      treadCnt=80 ok
      treadCnt=28 ok
      treadCnt=44 ok
      [ runs for several hous until problem shows ... ]
      treadCnt=88 ok
      treadCnt=66 ok
      treadCnt=91 ok
      treadCnt=0 ok
      treadCnt=36 ok
      treadCnt=10 ok
      treadCnt=26 ok
      treadCnt=44 ok
      treadCnt=77 ok
      treadCnt=96 ok
      treadCnt=5 ok
      treadCnt=29 ok
      treadCnt=8 ok
      treadCnt=17 ok
      treadCnt=13 ok
      treadCnt=86 ok
      treadCnt=19 ok
      treadCnt=60 ok
      treadCnt=65 ok
      treadCnt=83 ok
      treadCnt=90 ok
      treadCnt=46 ok
      treadCnt=21 ok
      treadCnt=38 ok
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 1 thread-no=42 soll=4 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 2 thread-no=42 soll=5 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 3 thread-no=42 soll=1 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 4 thread-no=42 soll=2 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 5 thread-no=42 soll=3 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 6 thread-no=42 soll=4 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 7 thread-no=42 soll=5 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 8 thread-no=42 soll=1 ist=00
      Mon Jul 07 23:55:07 CEST 2003 nokcnt = 9 thread-no=42 soll=2 ist=00
      [ ... ]

      Mon Jul 07 23:55:08 CEST 2003 nokcnt = 818 thread-no=32 soll=2 ist=00
      Mon Jul 07 23:55:08 CEST 2003 nokcnt = 818 thread-no=98 soll=3 ist=00
      Mon Jul 07 23:55:08 CEST 2003 nokcnt = 818 thread-no=47 soll=4 ist=00
      Mon Jul 07 23:55:08 CEST 2003 nokcnt = 818 thread-no=20 soll=2 ist=00
      nokcnt = 1000 ==> aborted
      %

      Return code is 255.

      Attachments

        Issue Links

          Activity

            People

              poonam Poonam Bajaj Parhar
              thlenz Thomas Lenz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: