SystemClock.sleep()&Thread.sleep()(延时)

1、SystemClock.sleep();—>在调用该函数的过程中不会发生InterruptedException异常,中断事件将要被延迟直到下一个中断事件。
2、Thread.sleep();—>在调用该函数的过程中可能会发生InterruptedException异常。

SystemClock.sleep(long ms)源码:
在这里插入图片描述
发现 SystemClock.sleep() 其实调用的就是 Thread.sleep()方法,除了抛不抛异常的区别外,本质的区别是:
SystemClock.sleep()不能被中断,无论如何都会让当前线程休眠指定的时间
而Thread.sleep()可以被中断,有可能在指定的休眠时间前被中断

发布了77 篇原创文章 · 获赞 411 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/qq_42761395/article/details/100057666