Kev sib piv thiab sib pauv ua haujlwm li cas?
Kev sib piv thiab sib pauv ua haujlwm li cas?

Video: Kev sib piv thiab sib pauv ua haujlwm li cas?

Video: Kev sib piv thiab sib pauv ua haujlwm li cas?
Video: 7 nqi lus qhia, piv kev kawm thiab kev ua neej sib txawv li cas? 2024, Kaum ib hlis
Anonim

Sib piv-thiab-swap . Hauv computer science, piv-thiab-swap (CAS) yog ib qho kev qhia atomic siv hauv multithreading kom ua tiav synchronization. Nws piv cov ntsiab lus ntawm qhov chaw nco nrog tus nqi muab thiab, tsuas yog lawv yog tib yam, hloov cov ntsiab lus ntawm qhov chaw nco ntawd mus rau tus nqi tshiab.

Tsis tas li ntawd, sib pauv thiab sib piv ua haujlwm hauv Java li cas?

Cov piv-thiab-swap (CAS) cov lus qhia yog ib qho kev qhia tsis cuam tshuam uas nyeem qhov chaw nco, sib piv cov nqi nyeem nrog tus nqi xav tau, thiab khaws tus nqi tshiab hauv qhov chaw nco thaum nyeem tus nqi sib tw nrog tus nqi xav tau. Txwv tsis pub, tsis muaj dab tsi ua.

Tom qab ntawd, lo lus nug yog, AtomicInteger ua haujlwm li cas hauv Java? Cov AtomicInteger chav kawm tiv thaiv tus nqi hauv qab los ntawm kev muab cov txheej txheem ua haujlwm atomic ntawm tus nqi. Nws yuav tsum tsis txhob siv los hloov rau ib chav Integer. Cov AtomicInteger chav kawm yog ib feem ntawm java ua . atomic pob txij li thaum Java 1.5.

Tsis tas li ntawd, cov lus qhia atomic yog dab tsi?

cov lus qhia atomic yog atomic nco cov lus qhia uas tuaj yeem ua synchronizing lossis tsis yog synchronizing, tag nrho tsuas yog atomic_ld yog nyeem-hloov-sau cov lus qhia (saib Memory Model). Syntax. Kev piav qhia ntawm Atomic thiab Atomic Tsis Rov Qab Cov lus qhia.

Dab tsi yog atomic reference nyob rau hauv Java?

Cov AtomicReference chav kawm muab ib yam khoom siv variable uas yuav nyeem tau thiab sau atomically. Los ntawm atomic txhais tau hais tias ntau cov xov sim hloov qhov qub AtomicReference (piv txwv li nrog kev sib piv-thiab-swap ua haujlwm) yuav tsis ua rau AtomicReference xaus rau hauv lub xeev tsis sib haum.

Pom zoo: