Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JNI and NSSelector



"Nathan V. Roberts" <email@hidden>

>I have a Java Cocoa app, a timer, that depends on the system clock
>(System.currentTimeMillis()). It happens that when you awake from
>sleep, for the first few seconds (about 10 on my 400 MHz Pismo), the
>clock is in the past -- it ticks from the time it was put to sleep.
>And, then, suddenly, it jumps. This is just a display issue, unless
>the user starts or stops the timer while the clock is in the past: if
>starts, the timer will tick normally for a few seconds and then
>(possibly after the user has obscured my app) both clock and timer
>will jump, possibly hours or days depending on the length of sleep.
>If the user stops the timer, the timer will not jump with the clock,
>and so will be short by the amount of time the clock jumps.

Wouldn't it be simpler to just avoid System.currentTimeMillis() entirely,
and use a different time-base that doesn't jump? Don't "beat around the
bush" of the problem, go straight to the root of it.

I don't know if the microsecond timer jumps or not, but it would be worth
looking at. If it jumps, it still might be easier to make it work, simply
because you could write a single JNI function in C, and inside the C code
you'd handle all the wake/sleep callbacks. In other words, if the timer
value is requested during the "pre-jump" period after wakeup, the function
itself just blocks until the value is correct. In general, this would be
bad, but it might work here.

You might be able to change it so that the blocking occurred only if the
timer was started or stopped during the pre-jump interval.

Or maybe you can use the Unix timer, which I think ticks at 100 Hz (10 ms
resolution). Since it's also the kernel time-slice timer, I doubt that
it's wrong for long after wakeup.

In any case, experimenting to find a better time-source sounds much easier
to me than dealing with various kinds of callbacks.

-- GG
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.