2024年4月28日发(作者:)
源码分析
和源码分析
一、在Android中休眠3s钟有2中方法:
1、(3000);
2、(3000);
二、通过系统源码区别
1、(long ms)源码:
static void sleep(long ms)
2. {
start = uptimeMillis();
duration = ms;
n interrupted = false;
{
{
8. (duration);
9. }
(InterruptedException e) {
11. interrupted = true;
12. }
13. duration = start + ms - uptimeMillis();
14. } while (duration > 0);
15.
(interrupted) {
17.// Important: we don't want to quietly eat an interrupt()
event,
18.// so we make sure to re-interrupt the thread so that the
next
19.// call to () or () will be interrupted.
20. tThread().interrupt();
21. }
22. }
有源码可知还是调用
(long time)源码:
static void sleep(long time) throws
InterruptedException {
2. (time, 0);
3. }
[java]
static void sleep(long millis,
InterruptedException
{
2. (millis, nanos);
3. }
[java]view plain copy
print?
1.最终调用到
nanos) throws int
发布评论