Puas yog Vector xov muaj kev nyab xeeb hauv Java?
Puas yog Vector xov muaj kev nyab xeeb hauv Java?

Video: Puas yog Vector xov muaj kev nyab xeeb hauv Java?

Video: Puas yog Vector xov muaj kev nyab xeeb hauv Java?
Video: Tsis Yog Kev Npau Suav(Dreams) - Bleu Thao 2024, Hlis ntuj nqeg
Anonim

Vector txoj kev yog tag nrho synchronized. Yog li siv nws los ntawm ntau yam xov yog " nyab xeeb ". Koj tsuas yog yuav tsum tau synchronize yog tias koj xav tau cov txheej txheem nyeem-kuaj-sau ua atomic. Synchronizing koj tus kheej txoj kev tsis tas yuav ua rau koj cov cai xov - nyab xeeb rau cov xwm txheej ntawd.

Ua raws li qhov no saib, cov npe xov puas muaj kev nyab xeeb hauv Java?

Qhov tseeb, tag nrho cov chav kawm sau (tshwj tsis yog Vector thiab Hashtable) hauv java ua . util pob tsis yog xov - nyab xeeb . Yog vim li cas qhov tshiab kev sau ( Sau npe , Teeb, Daim Ntawv Qhia, thiab lwm yam) muab tsis muaj kev tswj hwm ntawm txhua qhov los muab kev ua haujlwm siab tshaj plaws hauv cov ntawv thov ib leeg.

Ib yam li ntawd, cov khoom sau twg yog xov zoo hauv Java? A xov - nyab xeeb chav kawm yog ib chav kawm uas lav lub xeev sab hauv ntawm chav kawm nrog rau cov txiaj ntsig rov qab los ntawm cov txheej txheem, yog qhov tseeb thaum hu ua concurrently los ntawm ntau yam xov . Cov sau cov chav kawm uas yog xov - nyab xeeb hauv Java yog Stack, Vector, Properties, Hashtable, thiab lwm yam.

Khaws qhov no hauv kev txiav txim siab, yog Java HashSet xov zoo?

HashSet tsis yog Xov xwm nyab xeeb HashSet hauv Java tsis yog xov nyab xeeb raws li nws tsis synchronized los ntawm lub neej ntawd. Yog koj siv HashSet nyob rau hauv ib tug multi-threaded ib puag ncig uas nws yog accessed los ntawm ntau yam xov concurrently thiab structurally hloov ib yam nkaus thiab txawm ib tug xov ces nws yuav tsum tau synchronized externally.

Dab tsi yog xov zoo ArrayList lossis vector?

Vector yog qeeb li nws yog xov nyab xeeb . Hauv kev sib piv ArrayList yog ceev raws li nws tsis synchronized. Yog li hauv ArrayList ob lossis ntau dua xov tuaj yeem nkag mus rau tus lej tib lub sijhawm, thaum Vector yog txwv rau ib qho xov ntawm ib lub sijhawm. A Vector defaults rau doubling loj ntawm nws array.

Pom zoo: