transient and volatile variables ???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, February 18, 2002 10:08 AM

Hi, I would like to know what is the different between a normal, transient and volatile variables.



When should I use one or other ??


Thanks

Re: transient and volatile variables ???

Posted By:   Anonymous  
Posted On:   Monday, February 18, 2002 11:06 AM

The transient and volatile variables are rather rarely used.


Transient means that the variable won't be serialized with the rest of the object. This means that this variable is not kept when the object is written to disk or over a network socket. The typical example of a transient variable is a password kept in a User object, that shouldn't be serialized for security reasons.


volatile is even more exotic: it means that the variable is modified by multiple threads asynchronously. The VM should get this variable from memory each time it is used, and write it to memory when it is changed (instead of keeping it cached in registers or so...)


To be honest ... I've written quite a lot of Java code, and I've never used "volatile", and "transient" only one or two times ...



Regards,


G√ľnther.

http://www.javacoding.net

About | Sitemap | Contact