volatile关键字
筱米加步枪
posted @ 2010年3月09日 01:31
in [ JavaSE ]
with tags
volatile
, 1449 阅读
今天看《head first》时,无意中发现了volatile关键字~~百度~~
volatile是在多线程中使用的,平常我们声明一个变量,比如int x=1,那么在多线程中的时候,每个线程都有这个变量的一份拷贝,所以每个线程保存的值可以和“主”存区域的值不同(补充:“主”存区域保留的是变量的准确值)。
使用volatile修饰的变量,在所有的线程当中必须是同步的,一个线程改变了他的值,其他线程也会获得改变的这个值,他会不允许线程中有和“主”存区域不同的值,因此,用valatile修饰过的变量存取会更耗资源些。
2024年1月19日 06:15
JNANABHUMI AP offers the most recent information on education. The primary idea or goal of this website has been to offer comprehensive resources with information on any subject that can be accessed online. To make sure that every reader finds out what they should know about the subject they are interested in and jnanabhumiap.in links to our content.Jnanabhumi AP is a startup founded by enthusiastic bloggers and webmasters who are driven to produce interesting, factual, and well-written content. We are similar to an online community where you can find a variety of resources, information, and topics about newsworthy events or daily occurrences.