Monday, December 19, 2011

what is volatile keyword in java?

Volatile is keyword in java which is applicable to member variables only.

what does it mean if we declare a transient member variable in an object.

In the multithreaded applications, state of any object can be modified asynchronously by multple threads

This causes the consistency to the state among different concurrent threads.

To maintain the consistence between all the threads for that state of an object we can declare member variable as transient.

Whenever thread is going to execute the object, it tries to get the state of an object from memory, and save the state after thread execution is over, so that object's state can be consistent among concurent multiple threads.


private volatile String mState;


Note: Only a member of this blog may post a comment.