Dab tsi yog qhov pib tub nkeeg hauv Singleton?
Dab tsi yog qhov pib tub nkeeg hauv Singleton?

Video: Dab tsi yog qhov pib tub nkeeg hauv Singleton?

Video: Dab tsi yog qhov pib tub nkeeg hauv Singleton?
Video: Qis muag ua neej 7/14/2018 2024, Kaum ib hlis
Anonim

Lazy Initialization yog ib txoj kev uas ib tug ncua lub kev xav ntawm ib yam khoom mus txog thaum nws thawj zaug siv. Hauv lwm lo lus, piv txwv ntawm chav kawm yog tsim thaum nws yuav tsum tau siv thawj zaug. Lub tswv yim tom qab no yog kom tsis txhob muaj qhov tsim piv txwv tsim nyog.

Ntawm no, dab tsi yog tub nkeeg pib pib hauv Java?

Lazy pib yog ib qho kev ua tau zoo. Nws yog siv thaum cov ntaub ntawv suav tias yog 'kim' rau qee qhov laj thawj. Piv txwv li: yog tias tus nqi hashCode rau ib yam khoom yuav tsis xav tau los ntawm nws tus neeg hu xov tooj, ib txwm suav tus hashCode rau txhua qhov ntawm cov khoom yuav xav tias tsis tsim nyog.

Ib tug kuj yuav nug, ua li cas koj rhuav ib singleton? Serialization yog siv los hloov cov khoom ntawm byte kwj thiab txuag hauv cov ntaub ntawv lossis xa hauv lub network. Piv txwv tias koj serialize ib yam khoom ntawm a singleton chav kawm. Tom qab ntawd yog tias koj de-serialize cov khoom ntawd nws yuav tsim ib qho piv txwv tshiab thiab li no tawg tus singleton qauv.

Yog li ntawd, dab tsi yog tub nkeeg thiab xav pib pib?

Lazy pib yog cov txheej txheem peb txwv cov khoom tsim kom txog thaum nws tsim los ntawm daim ntawv thov code. Hauv lwm txoj kev kev xav pib tsim cov khoom ua ntej thiab tsuas yog tom qab pib daim ntawv thov lossis module. Qhov no yuav pab tau yog tias cov khoom yuav tsum tau ua thiab hauv txhua qhov kev ua haujlwm.

Dab tsi yog kev siv cov chav kawm singleton?

Hauv Java Singleton qauv yuav xyuas kom meej tias tsuas muaj ib qho piv txwv ntawm ib chav kawm yog tsim nyob rau hauv Java Virtual Machine. Nws yog siv los muab lub ntiaj teb point ntawm kev nkag mus rau cov khoom. Nyob rau hauv cov nqe lus ntawm kev siv siv Singleton cov qauv yog siv hauv kev nkag, caches, xov pas dej, configuration settings, ntaus ntawv tsav tsheb khoom.

Pom zoo: