Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   System.currentTimeMillis gives wrong time (http://www.velocityreviews.com/forums/t146032-system-currenttimemillis-gives-wrong-time.html)

Alex 09-06-2005 10:58 PM

System.currentTimeMillis gives wrong time
 
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


Joan 09-07-2005 12:21 AM

Re: System.currentTimeMillis gives wrong time
 

"Alex" <alexkuzn@gmail.com> wrote in message
news:1126047528.719387.121930@g44g2000cwa.googlegr 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.


Roedy Green 09-07-2005 12:58 AM

Re: System.currentTimeMillis gives wrong time
 
On 6 Sep 2005 15:58:48 -0700, "Alex" <alexkuzn@gmail.com> 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.

Roedy Green 09-07-2005 01:16 AM

Re: System.currentTimeMillis gives wrong time
 
On 6 Sep 2005 15:58:48 -0700, "Alex" <alexkuzn@gmail.com> 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.

Alex 09-07-2005 06:44 AM

Re: System.currentTimeMillis gives wrong time
 
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.


Andrew Thompson 09-07-2005 07:41 AM

Re: System.currentTimeMillis gives wrong time
 
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'

john@wezayzo.com 09-07-2005 07:47 AM

Re: System.currentTimeMillis gives wrong time
 
> 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 ? :-)

Gordon Beaton 09-07-2005 08:00 AM

Re: System.currentTimeMillis gives wrong time
 
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

Chris Uppal 09-07-2005 08:19 AM

Re: System.currentTimeMillis gives wrong time
 
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



Andrew Thompson 09-07-2005 10:39 AM

Re: System.currentTimeMillis gives wrong time
 
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'


All times are GMT. The time now is 08:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.