Operating System - Linux
1745794 Members
3916 Online
108722 Solutions
New Discussion юеВ

Re: java currentTimeMillis() not OK when date changed while programm running.

 
Antonio Cardoso_1
Trusted Contributor

java currentTimeMillis() not OK when date changed while programm running.

It seems that a java program running on HP-UX 11iv1 (rp4440, b2600) doesn't see the correct time using currentTimeMillis() if the date command was used to update current time while the program is running.

=> the main class hereafter gets the current time each 5 seconds and prints it to screen.
- On a XP PC, the date and time is correctly updated after I change it on the desktop while the program is running.
- On a HP-UX system, the date/time update is not seen !!

This looks like a bug ?

-----------------------------------
import java.util.*;

public class Test
{
public static void main(String[] args) {
Date date = new Date();

while(true) {
date.setTime(System.currentTimeMillis());
System.out.println(date);
try {
Thread.sleep(5000);
} catch (Exception e) {
System.err.println(e);
}
}
}
}
3 REPLIES 3
Arunvijai_4
Honored Contributor

Re: java currentTimeMillis() not OK when date changed while programm running.

Here is my output from 11.11

# /opt/java1.4/bin/java Test
Mon Oct 24 10:09:12 EDT 2005
Mon Oct 24 10:09:17 EDT 2005
Mon Oct 24 10:09:22 EDT 2005
Mon Oct 24 10:09:27 EDT 2005
Mon Oct 24 10:09:32 EDT 2005
Mon Oct 24 10:09:37 EDT 2005
Mon Oct 24 10:09:42 EDT 2005

What version of java you are running ?
Also check# date

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Antonio Cardoso_1
Trusted Contributor

Re: java currentTimeMillis() not OK when date changed while programm running.

I'm using Java 1.4.2-04.

I've got a similar output:
$ java Test
Mon Oct 24 16:41:26 CEST 2005
Mon Oct 24 16:41:31 CEST 2005
Mon Oct 24 16:41:36 CEST 2005
Mon Oct 24 16:41:41 CEST 2005

The problem is when date is changed in the system while this program runs, it is not seen in the program, unless I quit and re-run it, for example, I entered the command :
date -u 10241640
while it was running for display above (between 16:41:31 and 16:41:36), and we can see that the program continues updating 5 and 5 seconds from the initial time. We only get the correct time after stopping/restarting the programm.

On a XP system, I get a correct "live" update of system time in the running programm:
C:\Documents and Settings\Administrator>java Test
Mon Oct 24 16:47:18 GMT+07:00 2005
Mon Oct 24 16:47:23 GMT+07:00 2005
Mon Oct 24 16:47:28 GMT+07:00 2005
Mon Oct 24 16:47:33 GMT+07:00 2005
Mon Oct 24 16:46:36 GMT+07:00 2005
Mon Oct 24 16:46:41 GMT+07:00 2005
Mon Oct 24 16:46:46 GMT+07:00 2005
Mon Oct 24 16:47:54 GMT+07:00 2005
Mon Oct 24 16:47:59 GMT+07:00 2005

(date aketered twice at 16:47:35 1mn back and
after 16:46:46 a bit more than 1mn forth).
Paul J Harris
New Member

Re: java currentTimeMillis() not OK when date changed while programm running.

Just though I'd update this as I spent ages searching for a solution to this problem and there's no resolution in this thread...

Basically, it's a deliberate HP ploy done for performance reasons:

http://www.hp.com/products1/unix/java/java2/sdkrte14/infolibrary/sdk_rnotes_1.4.2.03.html#date_time