Dab tsi yog tsis synchronization hauv Java?
Dab tsi yog tsis synchronization hauv Java?

Video: Dab tsi yog tsis synchronization hauv Java?

Video: Dab tsi yog tsis synchronization hauv Java?
Video: Muaj tsis ntshai tuag 7/1/2018 2024, Kaum ib hlis
Anonim

Tsis yog - Synchronized txhais tau hais tias ob lossis ntau lub xov tuaj yeem nkag mus rau cov txheej txheem ntawm cov chav kawm tshwj xeeb ntawm txhua lub sijhawm. StringBuilder yog ib qho piv txwv ntawm a tsis yog - synchronized chav kawm. Feem ntau, a tsis yog - synchronized chav kawm tsis muaj xov zoo. (tab sis qee yam tsis yog - synchronized cov chav kawm yog xov-zoo)

Ib yam li ntawd, tib neeg nug, dab tsi yog lub ntsiab lus ntawm kev tsis sib haum xeeb?

Txhais ntawm unsynchronized.: tsis yog ua haujlwm lossis tshwm sim tib lub sijhawm: tsis synchronized unsynchronized moos unsynchronized txav.

Dab tsi yog synchronization hauv Java? Synchronization hauv java yog lub peev xwm los tswj kev nkag tau ntawm ntau cov xov rau txhua qhov chaw sib koom. Java Synchronization yog qhov kev xaiv zoo dua qhov uas peb xav tso cai rau ib qho xov nkaus xwb nkag mus rau cov peev txheej sib koom.

Tsis tas li ntawd, dab tsi yog txhais los ntawm synchronized thiab unsynchronized hauv Java?

Synchronized nkag mus txhais tau tias tias koj muaj qee yam kev xauv nkag rau cov ntaub ntawv. Qhov no tuaj yeem qhia tau los ntawm kev siv lub synchronized lo lus tseem ceeb los yog los ntawm kev siv qee cov qib siab tsim los ntawm cov java ua . Unsynchronized nkag mus txhais tau tias tias koj tsis muaj kev xauv nkag thaum nkag mus rau cov ntaub ntawv.

Nws txhais li cas ArrayList tsis synchronized?

Nws txhais tau tias tias eg ArrayList tsis yog guaranteed yuav threadsafe. Ua synchronized txhais tau tias tias txhua txoj haujlwm yog xov zoo - yog tias koj siv tib yam Array List los ntawm ob threads tib lub sijhawm, lawv ua tau 't corrupt lub xeev. Txawm li cas los xij, qhov no ua nws qeeb dua.

Pom zoo: