thread sleepSystemClock.sleep和Thread.sleep的区别

thread sleep  时间:2022-02-21  阅读:()

SystemClock.sleep和Thread.sleep的区别

在Java中我们处理线程同步问题时,处理延迟可能会使用Thread类的sleep方法,这里抛开concurrent类的一些方法,其实 Android平台还提供了一个SystemClock.sleep方法,它们有什么区别呢? 我们每次调用Thread.sleep时可能会出现InterruptedException异常,而SystemClock.sleep方法则不会,在 SDK上有这样的描述,它将会忽略中断异常。 Three different clocks are available, and they should not be confused: System.currentTimeMillis() is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the work (see setCurrentTimeMillis(long)), so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock. If you are using System.currentTimeMillis(), consider listening to the ACTION_TIME_TICK, ACTION_TIME_CHANGED and ACTION_TIMEZONE_CHANGED Intent broadcasts to find out when the time changes. uptimeMillis() is counted in milliseconds since the system was booted. This clock s when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms. This is the basis for most interval timing such as Thread.sleep(millls), Object.wait(millis), and System.nanoTime(). This clock is guaranteed to be monotonic, and is the mended basis for the general purpose interval timing of user interface events, performance measurements, and anything else that does not need to measure elapsed time during device sleep. Most methods that ept a timestamp value expect the uptimeMillis() clock. elapsedRealtime() is counted in milliseconds since the system was booted, including deep sleep. This clock should be used when measuring time intervals that may span periods of system sleep. There are several mechanisms for controlling the timing of events: Standard functions like Thread.sleep(millis) and Object.wait(millis) are always available. These functions use the uptimeMillis() clock; if the device enters sleep, the remainder of the time will be postponed until the device wakes up. These synchronous functions may be interrupted with Thread.interrupt(), and you must handle InterruptedException. SystemClock.sleep(millis) is a utility function very similar to Thread.sleep(millis), but it ignores InterruptedException. Use this function for delays if you do not use Thread.interrupt(), as it will preserve the interrupted state of the thread.

RackNerd:特价美国服务器促销,高配低价,美国多机房可选择,双E526**+AMD3700+NVMe

racknerd怎么样?racknerd今天发布了几款美国特价独立服务器的促销,本次商家主推高配置的服务器,各个配置给的都比较高,有Intel和AMD两种,硬盘也有NVMe和SSD等多咱组合可以选择,机房目前有夏洛特、洛杉矶、犹他州可以选择,性价比很高,有需要独服的朋友可以看看。点击进入:racknerd官方网站RackNerd暑假独服促销:CPU:双E5-2680v3 (24核心,48线程)内存...

Sharktech云服务器35折年付33美元起,2G内存/40G硬盘/4TB流量/多机房可选

Sharktech又称SK或者鲨鱼机房,是一家主打高防产品的国外商家,成立于2003年,提供的产品包括独立服务器租用、VPS云服务器等,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹等。之前我们经常分享商家提供的独立服务器产品,近期主机商针对云虚拟服务器(CVS)提供优惠码,优惠后XS套餐年付最低仅33.39美元起,支持使用支付宝、PayPal、信用卡等付款方式。下面以XS套餐为例,分享产品配...

特网云57元,香港云主机 1核 1G 10M宽带1G(防御)

特网云官網特网云服务器在硬件级别上实现云主机之间的完全隔离;采用高端服务器进行部署,同时采用集中的管理与监控,确保业务稳定可靠,搭建纯SSD架构的高性能企业级云服务器,同时采用Intel Haswell CPU、高频DDR4内存、高速Sas3 SSD闪存作为底层硬件配置,分钟级响应速度,特网云采用自带硬防节点,部分节点享免费20G防御,可实现300G防御峰值,有效防御DDoS、CC等恶意攻击,保障...

thread sleep为你推荐
excel计算公式excel表格如何用公式计算加减乘除混合运算匹配函数vlookup函数的使用方法 Excel中vlookup函数怎么用企业资源管理系统企业内部管理系统有哪些知识分享平台知识付费平台有哪些?网络审计什么叫网络会计师事务所人肉搜索引擎怎样使用人肉搜索引擎?assemblyinfoasp.net这几个文件是干什么的?什么是生态系统生态系统的功能有什么?activitygroupactivityGroup子activity跳转的问题bt代理为什么用代理下载BT非常非常慢啊?
cc域名 香港vps99idc simcentric 空间打开慢 火车票抢票攻略 idc资讯 183是联通还是移动 129邮箱 php空间购买 免费高速空间 香港新世界中心 in域名 新睿云 空间登录首页 智能dns解析 国外的代理服务器 lamp什么意思 实惠 攻击服务器 杭州电信 更多