Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > System.currentTimeMillis gives wrong time

Reply
Thread Tools

System.currentTimeMillis gives wrong time

 
 
Alex
Guest
Posts: n/a
 
      09-06-2005
In my program I have a System.currentTimeMillis() in a loop. Every
couple second I print out current time returned by this function on the
screen.
I returns correct time but after running for about an hour it starts
returning time which is 10 minutes late. It happens not once but in
multiple cycles.
Then eventuall it starts returning correct time again.

It really puzzles me. Do you have any suggestions.
This is a multithreaded application.

Thanks,
Alex

 
Reply With Quote
 
 
 
 
Joan
Guest
Posts: n/a
 
      09-07-2005

"Alex" <> wrote in message
news: oups.com...
> In my program I have a System.currentTimeMillis() in a loop.
> Every
> couple second I print out current time returned by this
> function on the
> screen.
> I returns correct time but after running for about an hour it
> starts
> returning time which is 10 minutes late. It happens not once
> but in
> multiple cycles.
> Then eventuall it starts returning correct time again.
>
> It really puzzles me. Do you have any suggestions.
> This is a multithreaded application.
>
> Thanks,
> Alex


I did a similar thing with a JLabel, but it only got behind a
second or two.
I think the thread you are using for this is not running as often
as it
needs to.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-07-2005
On 6 Sep 2005 15:58:48 -0700, "Alex" <> wrote or
quoted :

>It really puzzles me. Do you have any suggestions.


Is the output getting stuck in a buffer for 10 minutes?

Is your clock in the bottom right of your screen accurate?

Are you running something high priority and so CPU intensive that
could be causing timer ticks to be lost?

You can try running SetClock at various times during your run to see
how badly out it is really, verse what you buffer says.

see http://mindprod.com/jgloss/setclock.html

Clock malfunctions have not been much of a problem since DOS days, so
I most strongly suspect the problem is buffering. Try flush.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-07-2005
On 6 Sep 2005 15:58:48 -0700, "Alex" <> wrote or
quoted :

>In my program I have a System.currentTimeMillis() in a loop. Every
>couple second I print out current time returned by this function on the
>screen.


"print" has many different meanings. If you mean display on the
screen, perhaps the thread that is updating the display is getting
blocked or not triggered often enough.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Alex
Guest
Posts: n/a
 
      09-07-2005
Simplified example of what's happening:
System.currentTimeMillis() gives me lets say 1000, 1001, 1002, 1003
etc. and then suddenly 1000 again. It's the same thread. It's not just
a delay because of the buffer problems. It literally goes back in time

I use System.out.prinln() to print time.

I can't even imagine what might cause this.

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-07-2005
On 6 Sep 2005 23:44:17 -0700, Alex wrote:

> Simplified example of what's happening:
> System.currentTimeMillis() gives me lets say


*

>..1000, 1001, 1002, 1003
> etc. and then suddenly 1000 again.


* 'Lets say' you give us numbers from an actual run, rather
than numbers that you have positted based on your (lack of)
understanding of the problem.

As an aside, OS's generally have a 'time granularity' that
is around 20-50mseconds, from memory.

What is the biggest drift from '1000' that you have seen?

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"The storm broke with a violent flash of lightning, and an apalling crash
of thunder.."
Severed Heads 'Dead Eyes Opened'
 
Reply With Quote
 
john@wezayzo.com
Guest
Posts: n/a
 
      09-07-2005
> Simplified example of what's happening:
> System.currentTimeMillis() gives me lets say 1000, 1001, 1002, 1003
> etc. and then suddenly 1000 again. It's the same thread. It's not just
> a delay because of the buffer problems. It literally goes back in time.
> I use System.out.prinln() to print time. I can't even imagine what
> might cause this.


I gues you are stuck in an episode of The Twilight Zone ...

Do you see other strange things happening around you ?
Is there a talking cat with you, or multiple clones of your
spouse ?
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-07-2005
On 6 Sep 2005 23:44:17 -0700, Alex wrote:
> Simplified example of what's happening:
> System.currentTimeMillis() gives me lets say 1000, 1001, 1002, 1003
> etc. and then suddenly 1000 again. It's the same thread. It's not just
> a delay because of the buffer problems. It literally goes back in time
>
> I use System.out.prinln() to print time.
>
> I can't even imagine what might cause this.


Another process changing the system time.

On Unix, ntp does this transparently without causing the time to jump
or go backwards.

On Windows, I have no idea but it wouldn't surprise me if
"automatically synchronize time with an internet server" made that
kind of periodic adjustment.

On the other hand, there could very well be something wrong with the
code you neglected to post.

In any case, I seriously doubt that System.currentTimeMillis() itself
is the problem.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      09-07-2005
Alex wrote:

> Simplified example of what's happening:
> System.currentTimeMillis() gives me lets say 1000, 1001, 1002, 1003
> etc. and then suddenly 1000 again. It's the same thread. It's not just
> a delay because of the buffer problems. It literally goes back in time
>
> I use System.out.prinln() to print time.
>
> I can't even imagine what might cause this.


Neither can I. Which makes me suspect that (however unlikely it may seem)
there must be a problem in your code. Can you reduce it to a self contained
example that is small enough to post ?

-- chris


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      09-07-2005
On Wed, 7 Sep 2005 09:19:19 +0100, Chris Uppal wrote:

> Can you reduce it to a self contained
> example that is small enough to post ?


For tips on preparing self contained (small) examples, see..
<http://www.physci.org/codes/sscce.jsp>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"If we fall, others are rising.."
Paul Kelly 'From Little Things, Big Things Grow'
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting double by long gives wrong value. johnny boy C Programming 16 11-30-2009 08:07 AM
Keyboard gives wrong characters. Burnt2@crisp.org Computer Support 3 08-04-2008 06:26 PM
dhcp gives ip in wrong range to laptop -keevill- Wireless Networking 1 03-10-2008 01:47 PM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
REMOTE_ADDR gives a wrong IP address Sachin Singhal ASP General 5 11-11-2003 02:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57