sleep() 和 wait() 有什么区别?
2016-02-25 11:28
405 查看
sleep()方法是使线程停止一段时间的方法。在sleep 时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非
a.“醒来”的线程具有更高的优先级 b.正在运行的线程因为其它原因而阻塞。
wait()是线程交互时,如果线程对一个同步对象x 发出一个wait()调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。
a.“醒来”的线程具有更高的优先级 b.正在运行的线程因为其它原因而阻塞。
wait()是线程交互时,如果线程对一个同步对象x 发出一个wait()调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。
相关文章推荐
- AIDL初探以及学习
- 收到的电邮附件为Winmail.dat?
- move_uploaded_file的failed to open stream错误处理
- move_uploaded_file的failed to open stream错误处理
- 错误提示:process launch failed: Security
- 淘汰人工的机器时代
- 在可以调用 OLE 之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的 Main 函数带有 STAThreadAttr
- linxu 中大量的close_wait 和 time_wait 处理
- 217. Contains Duplicate
- AIX ERRPT日志查询
- RAID5磁盘阵列配置
- Could not obtain transaction-synchronized Session for current thread 异常处理方式
- User Agent String explained
- 报错:Conversion to Dalvik format failed: Unable to execute dex:
- 217. Contains Duplicate
- Does Daemon Thread Exit with Main Thread?
- Exchange2010使用 Export-Mailbox cmdlet 将邮箱的内容移动到指定的邮箱文件夹
- HDU 3264 Open-air shopping malls(计算几何 && 二分优化)
- hdu2467 String painter(区间dp)
- UVA253 Cube painting