Thanks a lot. Nice explanation. One question. Threads born after instance is not Null will directly go to loc "return instance; " , but at same time there will be many threads(let us take Thread B) that are waiting for lock and after they get lock , they will run "if(instance==null)" and will go inside , if we don't use 'volatile' keyword for variable 'instance'. Am i correct here or else tell me where i am going wrong ?
Thanks a lot. Nice explanation. One question. Threads born after instance is not Null will directly go to loc "return instance; " , but at same time there will be many threads(let us take Thread B) that are waiting for lock and after they get lock , they will run "if(instance==null)" and will go inside , if we don't use 'volatile' keyword for variable 'instance'. Am i correct here or else tell me where i am going wrong ?
ReplyDelete