All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hibegin.common.SleepUtils Maven / Gradle / Ivy

Go to download

Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project. Can quickly run embedded, Android devices

There is a newer version: 0.3.162
Show newest version
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