From owner-freebsd-questions@freebsd.org Wed Sep 2 12:31:25 2015 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1DC79C6B97 for ; Wed, 2 Sep 2015 12:31:25 +0000 (UTC) (envelope-from bsam@passap.ru) Received: from forward2m.mail.yandex.net (forward2m.mail.yandex.net [IPv6:2a02:6b8:0:2519::3:11]) by mx1.freebsd.org (Postfix) with ESMTP id AE9D3FC2 for ; Wed, 2 Sep 2015 12:31:25 +0000 (UTC) (envelope-from bsam@passap.ru) Received: from smtp4m.mail.yandex.net (smtp4m.mail.yandex.net [IPv6:2a02:6b8:0:2519::126]) by forward2m.mail.yandex.net (Yandex) with ESMTP id 2A26A5CA0D97 for ; Wed, 2 Sep 2015 15:31:17 +0300 (MSK) Received: from smtp4m.mail.yandex.net (localhost [127.0.0.1]) by smtp4m.mail.yandex.net (Yandex) with ESMTP id E90A9BE02CB for ; Wed, 2 Sep 2015 15:31:16 +0300 (MSK) Received: by smtp4m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id tvQdfnZ1iI-VGpO5MEG; Wed, 2 Sep 2015 15:31:16 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-ForeignMX: US To: freebsd-questions@freebsd.org From: Boris Samorodov Subject: java park and sleep issue X-Enigmail-Draft-Status: N1110 Message-ID: <55E6EC14.8020205@passap.ru> Date: Wed, 2 Sep 2015 15:31:16 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2015 12:31:26 -0000 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