wood burning stoves 2.0*
The moose likes Java in General and the fly likes Why volatile variable can't be serialized? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why volatile variable can Watch "Why volatile variable can New topic
Author

Why volatile variable can't be serialized?

subbu
Greenhorn

Joined: Dec 22, 2005
Posts: 2
Why volatile variable can't be serialized?


====regards<br />subbu
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"jkith"

Welcome to JavaRanch!

Can you please update your display name so it complies with our Naming Policy. You can do this here.

Thanks!


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 582
    
    7

jkith,

For you, why would one serialize a variable?

and,

Again for you, why would one specify a veriable as volitile?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61755
    
  67

Please reserve this forum for truly advanced questions. Moved to Java in General (intermediate).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subbu
Greenhorn

Joined: Dec 22, 2005
Posts: 2
In multithreaded environment to maintain the unique value of a particular field, we are using volatile.

Any reason why it can't be serialised.

If a particular memeber(field) declared as transient it will not be included while doing the serialization.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"subbu"

Thank you for taking the time to update your display name. Unfortunately a valid display name must have both a real-sounding first and last name. Please can you update it again. Thank you.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
As far as I know, and I have just skim-read the "volatile" section of the language spec and the introduction to the Serialisation spec, the "volatile" keyword has no effect on serialisation.

The "volatile" keyword, as you say, is about maintaining a consistent view of the field between threads. It is "transient" that controls serialisation. I could find no evidence of any link between the two keywords.

Did you actually try to serialise your volatile field? I would expect it to succeed.

Note that you can serialise even transient fields. It's only the *default* serialisation mechanism that does not serialise them. If you provide custom serialisation, which ain't too hard, you can put anything you like in the serialisation stream.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

Its a way to maintain the resources held by runtime objects.

Assume, you are using one file stream to read data in an object which you want to serialize.
Will it work after deserialization on other machine?. may or may not.

So all network,file,i/o,DB resources variables mainly used as transient variables, so that they will be reset to the runtime environemnt in which the object is deserialized.

Note: ofcourse to relase the resources too ...

More inputs are welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why volatile variable can't be serialized?