WordRider Home
Welcome! Log In Create A New Profile

Advanced

Timer Problem

Posted by cps 
cps
Timer Problem
December 10, 2013 01:35AM
Hi,

I've recently started using FreeRapid on OSX. There seems to be a problem with the program's countdown timer in that it runs very slow. As a simple test I've run a basic timer app in parallel with FreeRapid. At the moment the standalone countdown timer is showing 1:42 remaining while FreeRapid is showing 2:42. Bother were started at the same time with a three hour countdown period. I think the problem appeared after I upgraded to OSX 10.9 although I'm not certain about this.

Anyone else noticed this problem?
Re: Timer Problem
December 10, 2013 12:43PM
Can you run the attached test program and see if the sleep time is significantly more than 1000 milliseconds?

You can run it by opening a terminal, changing to the directory where you saved the .class file, and running "java SleepTest" without quotes.

Here's the source code if you want it:

Language: Java
public class SleepTest { public static void main(final String[] args) throws Exception { for (int i = 0; i < 20; i++) { testSleep(); } }   private static void testSleep() throws Exception { final long start = System.nanoTime(); Thread.sleep(1000); final long duration = (System.nanoTime() - start) / 1000000; System.out.println("Slept for " + duration + " ms"); } }
Attachments:
open | download - SleepTest.class (942 bytes)
cps
Re: Timer Problem
December 14, 2013 05:02AM
I ran the test. Here are the results:

chris$ java SleepTest
Slept for 1001 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1001 ms
Slept for 1001 ms
Slept for 1001 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1000 ms
Slept for 1001 ms
Slept for 1000 ms
Slept for 1001 ms
Slept for 1000 ms
Slept for 1000 ms

Seems to be working OK.
Re: Timer Problem
December 14, 2013 02:46PM
Hmm. Can you repeat the same procedure with this test?

Language: Java
import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.CountDownLatch;   public class SleepTest2 extends TimerTask { private final CountDownLatch latch = new CountDownLatch(1); private long lastTime; private int i;   public static void main(final String[] args) throws Exception { final Timer timer = new Timer();   SleepTest2 test = new SleepTest2(); timer.schedule(test, 0, 1000); test.latch.await();   test = new SleepTest2(); timer.scheduleAtFixedRate(test, 0, 1000); test.latch.await();   timer.cancel(); }   @Override public void run() { if (lastTime > 0) { final long duration = (System.nanoTime() - lastTime) / 1000000; System.out.println(i + ": Slept for " + duration + " ms"); } lastTime = System.nanoTime(); if (++i > 10) { cancel(); latch.countDown(); } } }
Attachments:
open | download - SleepTest2.class (1.4 KB)
cps
Re: Timer Problem
December 16, 2013 10:21AM
Here are the results of the second test:

New-MacBook:Downloads chris$ java SleepTest2
1: Slept for 1000 ms
2: Slept for 1000 ms
3: Slept for 1001 ms
4: Slept for 1000 ms
5: Slept for 1001 ms
6: Slept for 1001 ms
7: Slept for 999 ms
8: Slept for 1001 ms
9: Slept for 1000 ms
10: Slept for 1000 ms
1: Slept for 1001 ms
2: Slept for 999 ms
3: Slept for 1000 ms
4: Slept for 1000 ms
5: Slept for 998 ms
6: Slept for 1000 ms
7: Slept for 1000 ms
8: Slept for 1000 ms
9: Slept for 998 ms
10: Slept for 1001 ms
Re: Timer Problem
December 16, 2013 02:36PM
Weird. Does the countdown always run slow or only sometimes?
cps
Re: Timer Problem
December 18, 2013 12:03PM
ntoskrnl Wrote:
-------------------------------------------------------
> Weird. Does the countdown always run slow or only
> sometimes?

I'll check and let you know.
cps
Re: Timer Problem
December 19, 2013 12:58AM
Just wondering whether some of the new power saving technologies introduced in 10.9 might be causing this? See here:

[www.apple.com]

While I'm waiting I often have FreeRapid in the background or even minimised.
cps
Re: Timer Problem
December 19, 2013 01:53AM
Problem is definitely happening when the app is minimised but is not present when the app is in the foreground.

I've found an article that explains how to disable App Nap:

[reviews.cnet.com]

I'll give this a go and report back.
cps
Re: Timer Problem
December 19, 2013 04:26AM
Selecting "Prevent App Nap" appears to have fixed the problem.

Maybe this should be a "sticky" for Mac users?

Cheers,

Chris
Sorry, only registered users may post in this forum.

Click here to login