问题描述
详细描述Thismethodcontainsanunsynchronizedlazyinitializationofastaticfield.Afterthefieldisset,theobjectstoredintothatlocationisfurtherupdatedoraccessed.Thesettingofthefieldisvisibletootherthreadsassoonasitisset.Ifthefutheraccessesinthemethodthatsetthefieldservetoinitializetheobject,thenyouhaveaveryseriousmultithreadingbug,unlesssomethingelsepreventsanyotherthreadfromaccessingthestoredobjectuntilitisfullyinitialized.Evenifyoufeelconfidentthatthemethodisnevercalledbymultiplethreads,itmightbebettertonotsetthestaticfielduntilthevalueyouaresettingittoisfullypopulated/initialized.有谁能解释下吗?一直对这个问题很模棱两可,不胜感谢
解决方案
解决方案二:
该回复于2009-08-14 13:30:02被版主删除
时间: 2024-10-01 01:12:03