Java?е????Thread???
???????????? ???????[ 2014/3/10 9:19:16 ] ????????Java ??? Thread
????sleep??yield????
????1??sleep()?????????????????е????????????????????????????????????????????е????yield()???????????????????????????????????????е????
????2????????????sleep(long millis)???????????????????????millis???????????????????yield()?????????????????
????3??sleep()???????????InterruptedException??????yield()???????????????κ???
????4??sleep()??????yield()???????и?????????
?????????????????????????????????????е?????????????μ??????
????1???????????????????
????2?????????????????????Thread.sleep()????
????3?????????????????????Thread.yield()????
????4??????????????????????????????join()????
?????????wait()??notify()??notifyAll()??Object????????sleep()??yield()??Thread????????
????(1).?????wait??????wait()??wait(long timeout):
????void wait() ????????????????? notify() ?????? notifyAll() ??????????μ?????????
????void wait(long timeout) ????????????????? notify() ?????? notifyAll() ?????????????????????????????μ?????????
????wait()????????????????е?“?????”?????????????????е?????synchronized??????????????á?
????wait()??notify()??????????“?????”???в??????????????????synchronized??????synchronized??????н??е??á??????non- synchronized??????non-synchronized??????н??е??????????????????????? ???????IllegalMonitorStateException??????
????(2).Thread.sleep(long millis)????????????????????
????sleep(long)????????????????????????sleep()?????????????????????????У?
????sleep(long)??????????????????е?????????????????????????????????????е????
????sleep(long)????????????????
????(3).yield()??в?????
????sleep ?????????????е?????????????????????????????????????????????趨???yield ????????????ó?CPU?????????ó????????????趨???yield()???????????????
??????????yield()????????????2????? ????????????????????????????????????????У???? CPU ????????????????????????????????????????yield()???????“????”?????????л??????????????????????????
????sleep?????????????????????????л?????yield()????????????????????????????????????????ó??????????????Щ????CPU?????? ????????????У???????????????????е??? sleep ?????????????? I/O????????????????????????????н???????????????н????????л??????С?
????yield()????????????????????????????????yield()??????п??????????????????????????С?????yield()???????????????????е????
????volitile ????
????volatile????synchronized????????????volatile?????????synchronized?????壬????????????????????volatile??ε???????????????????????????
????volatile???????????壺
??????1??Java ?洢???????valatile?????????????????????????volatile??????????????????????????е??
??????2??volatile???????????????????У????????????????????????CPU????????????????????????ж??volatile??????????????????volatile??????????????????????????????????????????????????????????happens-before?????У??????valatile??????д???????????κζ????????????д??????????
????????volatile??????????????????volatile????????????????????volatile??ε???????????????volatile??????????????????????????????????????????仯???????????????????????????????
?????????????
??????????????????
????1??????????????????????????????????????????????????????????????????????????????????????????????????????????????????ж????????????顣????ν?????????????????????????????????????????????????????????????????????????????
????2??????????е??????
????3???????????????????synchronized???η????????????????????????(??Object.class????????this)?????????????????
????4????????????????????????????????ζ?????????????????У???????????????????????Thread.sleep()???????Thread.yield()????????????????????????????????е?????????????????
????5??synchronized??????????У?????????synchronized???ε???????????????????????????????????????????????synchronized???Ρ?
????6??synchronized ???????????????????????е???????????顣 ??????????????? this ??????????????????? ????? synchronized ???ε?????????У?????????????????? Class ??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11