< Java Programming < Keywords

volatile is a keyword.

When member variables are marked with this keyword, it changes the runtime behavior in a way that is noticeable when multiple threads access these variables. Without the volatile keyword, one thread could observe another thread update member variables in an order that is not consistent with what is specified in sourcecode. Unlike the synchronized keyword, concurrent access to a volatile field is allowed.

Syntax:

private volatile <member-variable>;
or 
volatile private <member-variable>;


For example:

private volatile changingVar;

See also:

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.