mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
优化ThreadUtil.safeSleep,使用System.nanoTime()
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.thread;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,4 +12,13 @@ public class ThreadUtilTest {
|
||||
|
||||
ThreadUtil.execute(() -> Assert.assertTrue(isValid));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeSleepTest() {
|
||||
final long sleepMillis = RandomUtil.randomLong(1, 1000);
|
||||
// 随机sleep时长,确保sleep时间足够
|
||||
final long l = System.currentTimeMillis();
|
||||
ThreadUtil.safeSleep(sleepMillis);
|
||||
Assert.assertTrue(System.currentTimeMillis() - l >= sleepMillis);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user