You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jörg Schaible <jo...@gmx.de> on 2005/12/14 22:13:42 UTC

Re: Gump & VM (was: [POLL] System.currentTimeMillis())

Jörg Schaible wrote:

> Hi folks,
> 
> I have written a generator for commons-id, that is based in the end on the
> system clock. Unfortunately I have sporadic failures in Gump that I cannot
> explain. I developed this on a Windows box, but had now a chance for a
> test with Linux. Suddenly I have also sporadic failing tests. First I
> thought my algorithm is flawed, but then I wrote this little unit test:
> 
>     
>     public void testSystemTimeIsIncreasing() {
>         long last = System.currentTimeMillis();
>         for (int i = 0; i < 50000; i++) {
>             long now = System.currentTimeMillis();
>             assertTrue("Iteration " + i,  now >= last);
>             last = now;
>         }
>     }
> 
> 
> Believe it or not, this test will quite always fail within the first 10000
> iterations on my Linux box. So how does this test behave on your boxes?
> Please also note OS and JDK ...

OK, I can analyse the situation. My current box was not totally synchronized
and I had a daemon running, that adjusted the time smoothly. After compete
synchronization the tests passes. Nevertheless, this does not solve the
Gump problem, since I know, that they have often problems with the system
time (we had last week one VM where 1 second exactly took 2 real ones). So
what can we do?

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: Gump & VM

Posted by "C. Grobmeier" <gr...@possessed.de>.
 > So what can we do?

I read about timers in the book "killer game programming in java" :-),
where this things are important. Maybe this is a direction for you.

Use the following instead of System.currentTimeMillis():

1) Suns undocumented Class (Java2): sun.misc.Perf

2) Java 5: System.nanoTime()

This two have a higher resolution than currentTimeMillis() and could help.

Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org