/** * Parks the current thread until the specified system time. This method attempts to unpark the * current thread immediately after <code>System.currentTimeMillis()</code> reaches the specified * value, if no other thread unparks it first. If the thread has been "preemptively unparked," * this method cancels that unparking and returns immediately. This method may also return * spuriously (that is, without the thread being told to unpark and without the indicated amount * of time elapsing). * * <p>See {@link java.util.concurrent.locks.LockSupport} for more in-depth information of the * behavior of this method. * * <p>This method must only be called when <code>this</code> is the current thread. * * @param time the time after which the thread should be unparked, in absolute * milliseconds-since-the-epoch * @hide for Unsafe */ public void parkUntil(long time) { VMThread vmt = vmThread; if (vmt == null) { // Running threads should always have an associated vmThread. throw new AssertionError(); } synchronized (vmt) { /* * Note: This conflates the two time bases of "wall clock" * time and "monotonic uptime" time. However, given that * the underlying system can only wait on monotonic time, * it is unclear if there is any way to avoid the * conflation. The downside here is that if, having * calculated the delay, the wall clock gets moved ahead, * this method may not return until well after the wall * clock has reached the originally designated time. The * reverse problem (the wall clock being turned back) * isn't a big deal, since this method is allowed to * spuriously return for any reason, and this situation * can safely be construed as just such a spurious return. */ long delayMillis = time - System.currentTimeMillis(); if (delayMillis <= 0) { parkState = ParkState.UNPARKED; } else { parkFor(delayMillis * NANOS_PER_MILLI); } } }