closed as not a real question by cherouvim, harto, Pascal Thivent, Jeff,ho1 Aug 27 '10 at 12:16
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.
22
|
The
volatile and transient access modifiers apply to fields of classes.
The
transient modifier tells the Java object serialization subsystem to exclude the field when serializing an instance of the class. When the object is then deserialized, the field will be initialized to the default value; i.e. null for a reference type, and zero or false for a primitive type. Note that the JLS (see 8.3.1.3) does not say what transient means, but defers to the Java Object Serialization Specification. Other non-standard serialization mechanisms may also pay attention to a field'stransient -ness.
The
volatile modifier tells the JVM that writes to the field should always be synchronously flushed to memory, and that reads of the field should always read from memory. This means that fields marked as volatile can be safely accessed and updated in a multi-thread application without using native or standard library-based synchronization. (This does not apply to long or double fields, which may be non-atomic on some JVMs. However, it always applies to reference-typed fields.) The relevant parts of the JLS are 8.3.1.4, 17.4 and 17.7. | ||||||||||||||||||||
|