Jump to content
Wikibooks The Free Textbook Project

Java Programming/Keywords/volatile

From Wikibooks, open books for an open world

This is the current revision of this page, as edited by Strange quark (discuss | contribs) at 18:48, 4 July 2017 (Fix categorization). The present address (URL) is a permanent link to this version.

Revision as of 18:48, 4 July 2017 by Strange quark (discuss | contribs) (Fix categorization)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

Computer code
privatevolatilechangingVar;


See also:

AltStyle によって変換されたページ (->オリジナル) /