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:
@@ -101,4 +101,13 @@ public class ThreadUtilTest {
|
||||
}, "线程 - " + x).start();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void safeSleepTest() {
|
||||
final long sleepMillis = RandomUtil.randomLong(1, 1000);
|
||||
// 随机sleep时长,确保sleep时间足够
|
||||
final long l = System.currentTimeMillis();
|
||||
ThreadUtil.safeSleep(sleepMillis);
|
||||
Assertions.assertTrue(System.currentTimeMillis() - l >= sleepMillis);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user