com.hibegin.common.SleepUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplewebserver Show documentation
Show all versions of simplewebserver Show documentation
Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project.
Can quickly run embedded, Android devices
package com.hibegin.common;
public class SleepUtils {
/**
* 无锁模式
*
* @param lockObject
* @param sleepInMs
* @return
* @throws InterruptedException
*/
public static int noCpuCompeteSleep(LockObject lockObject, int sleepInMs) throws InterruptedException {
lockObject.getLock().lock();
try {
long nanos = sleepInMs * 1000000L; // 转换为纳秒
while (nanos > 0) {
nanos = lockObject.getCondition().awaitNanos(nanos);
}
return sleepInMs;
} finally {
lockObject.getLock().unlock();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy