avatar
另一个入门问题。# Java - 爪哇娇娃
j*g
1
Assuming that an interrupted exception has NOT been thrown and that "
aLiveThread" is a runnable thread, which three guarantee that a thread will
leave the running state?
A yield()
B wait()
C sleep(1000)
D aLiveThread.join()
B and D 肯定是对的。
答案说A是错的,说即使调用yield()不一定会导致该Thread被换出。但我的理解是调用
yield()以后一定会被换出。但是如果没有更高prority的Thread的话,该Thread可能会
再次进入running状态。意思就是肯定会leave running, 但是可能马上就被换入。
答案说C是对的。我的印象是即使调用sleep()也不一定会导致Thread被换出。因为印象
以前在sun工作站上做的时候sleep(250)没有导致当前Thread被换出。
牛人指教一下?
avatar
m*t
2
I wouldn't sweat on A too much. It's just a matter of whether reading "
leaving the running state" literally. As long as everybody agrees that
yield() does not _always_ cause the thread to effectively yield the
processor, whether it literally leaves the "running" state in the state
diagram really is more theoretical than practical.
IIUC, in any decent JVM implementation, sleep() most certainly would cause a
thread to yeild control, because even if there aren't other application
threads suitable
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。