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

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

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-12-05
  • 2021-11-11
  • 2021-04-08
  • 2021-09-23
  • 2021-10-25
  • 2021-05-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-11-30
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案