Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Sep 2015 15:31:16 +0300
From:      Boris Samorodov <bsam@passap.ru>
To:        freebsd-questions@freebsd.org
Subject:   java park and sleep issue
Message-ID:  <55E6EC14.8020205@passap.ru>

next in thread | raw e-mail | index | archive | help
Hi All,


I'm a newcomer to the java world, so my questions may be too vague.

So, I've got an unexpected result at FreeBSD (r287323 amd64) and java
(openjdk version "1.7.0_80"):
-----
Starting...
For timeVal = 0; Time elapsed: 1 ms
For timeVal = 1; Time elapsed: 2000 ms
For timeVal = 2; Time elapsed: 3000 ms
For timeVal = 3; Time elapsed: 4000 ms
For timeVal = 4; Time elapsed: 5000 ms
-----

Linux (CentOS-6.6 x64) and java (java version "1.7.0_71") give a more
expected result:
-----
Starting...
For timeVal = 0; Time elapsed: 1 ms
For timeVal = 1; Time elapsed: 1056 ms
For timeVal = 2; Time elapsed: 2065 ms
For timeVal = 3; Time elapsed: 3066 ms
For timeVal = 4; Time elapsed: 4066 ms
-----

The testcase is:
-----
public class App {
    public static void main(String[] args) {
        System.out.println("Starting...");

        for (int expectedMS = 0; expectedMS < 5; expectedMS++) {
            long start = System.currentTimeMillis();

            for (int i = 0; i < 1000; i++)
                java.util.concurrent.locks.LockSupport.parkNanos((long)
1e6 * expectedMS);

            long stop = System.currentTimeMillis();
            System.out.println("For timeVal = " + expectedMS + "; Time
elapsed: " + (stop - start) + " ms");
        }

    }
}
-----

BTW, Thread.sleep() gives the same results both at FreeBSD and Linux.

Is it a real issue? Or may be it's just OK?

-- 
WBR, Boris Samorodov (bsam)
FreeBSD Committer, http://www.FreeBSD.org The Power To Serve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?55E6EC14.8020205>