Some insight here
http://www.javatuning.com/why-is-thread-sleep-inherently-inaccurate/


On 8/6/13 8:16 AM, "Daan Hoogland" <daan.hoogl...@gmail.com> wrote:

>H,
>
>I just had a time skew that seems impossible:
>
>if in the folowing test the sleep is 1000 it reports a failure saying
>the duration was 999. now I see at least some clock ticks around it so
>whats heppening? An overeager optimizer, maybe? I had to set it to
>1001 to make it work. This is not new code, it has been there since
>jan 24! So i ran it a few times.
>
>public class TestProfiler extends Log4jEnabledTestCase {
>    protected final static Logger s_logger =
>Logger.getLogger(TestProfiler.class);
>
>    @Test
>    public void testProfiler() {
>        s_logger.info("testProfiler() started");
>
>        Profiler pf = new Profiler();
>        pf.start();
>        try {
>            Thread.sleep(1001);
>        } catch (InterruptedException e) {
>        }
>        pf.stop();
>
>        s_logger.info("Duration : " + pf.getDuration());
>
>        Assert.assertTrue(pf.getDuration() >= 1000);
>
>        s_logger.info("testProfiler() stopped");
>    }
>}
>
>any clue welcome,
>Daan

Reply via email to