首页 > 编程语言 > 详细

线程中常用的一些方法

时间:2019-08-02 20:29:19      阅读:119      评论:0      收藏:0      [点我收藏+]

sleep() 属于Thread的方法,不释放锁,自动唤醒或者interrupt打断

wait() 属于Object的方法,释放锁,不会被自动唤醒,用notify() or notifyall()唤醒

notify() / notifyall()  唤醒 任意一个 / 全部 在此对象上等待的线程

Wakes up a single thread that is waiting on this object‘s
monitor. If any threads are waiting on this object, one of them
is chosen to be awakened. The choice is arbitrary and occurs at
the discretion of the implementation. A thread waits on an object‘s
monitor by calling one of the {@code wait} methods.

注:wait()和notify()\nofityall()是配合着使用,且是在多线程状态下。

join() https://www.cnblogs.com/DDiamondd/p/11290833.html

yield() : https://www.cnblogs.com/DDiamondd/p/11290942.html

 

线程中常用的一些方法

原文:https://www.cnblogs.com/DDiamondd/p/11290981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!