• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

how to use the transient keyword to improve the serialization/Deserialization

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Serialization and deserialization of objects is a CPU-intensive procedure and is likely to slow
down your application. Use the transient keyword to reduce the amount of data serialized."
 
Marshal
Posts: 74042
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you get that from? The transient keyword is not intended so much to reduce workload as to prevent secret data, eg passwords, being stored in such a fashion that they can easily be read. Is serialisation such an overhead that you need to worry about transient?
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Where did you get that from? The transient keyword is not intended so much to reduce workload as to prevent secret data, eg passwords, being stored in such a fashion that they can easily be read. Is serialisation such an overhead that you need to worry about transient?



My guess is that the OP wants to know if he could knock out certain members from being serialized by using transient, regardless of whether the data is sensitive.
 
keiwer villabona ruiz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Oracle GlassFish Server 3.1 Performance Tuning Guide"
 
Campbell Ritchie
Marshal
Posts: 74042
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Johnston wrote: . . . My guess is that the OP wants to know if he could knock out certain members from being serialized by using transient, regardless of whether the data is sensitive.

Yes, you can exclude fields from serialisation with the transient keyword. But why would you want to/

And thank you for the citation.
 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Bill Johnston wrote: . . . My guess is that the OP wants to know if he could knock out certain members from being serialized by using transient, regardless of whether the data is sensitive.

Yes, you can exclude fields from serialisation with the transient keyword. But why would you want to/

And thank you for the citation.



Reasonable question Campbell. That's for the OP to answer, as I was only posing it as a possible reason the OP might want to use the keyword.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

keiwer villabona ruiz wrote:"Serialization and deserialization of objects is a CPU-intensive procedure and is likely to slow
down your application. Use the transient keyword to reduce the amount of data serialized."


Welcome to CodeRanch!

As a matter of fact, the members marked as 'transient' are not serialized.

keiwer villabona ruiz wrote:how to use the transient keyword to improve the serialization/Deserialization


As mentioned above, you'll need to figure out which members of a class must be serialized and which members can be exempted from serialization(further, those members can be marked as transient). Please note that you might get improvement in 'performance' by not serializing all the members. This does not improve serialization, but simply bypasses the serialization process for that particular member.

I hope this helps.
 
Master Rancher
Posts: 4032
54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Bill Johnston wrote:

Yes, you can exclude fields from serialisation with the transient keyword. But why would you want to/


Umm... because Oracle told him to?

http://docs.oracle.com/cd/E26576_01/doc.312/e24936/tuning-apps.htm#abebg

Now of course we may disagree with that advice - it may well be premature optimization, and can easily be taken to excess. But aside from secrecy (which I do not think is the primary reason transient exists), there are plenty of classes that you can't or shouldn't serialize. For example a database or network connection - you might serialize the connection info, but not the actual connection. That gets re-connected after you reinstantiate the instance that needs it. Or an Xml parser, or other object with complex internals. Or any object of a library class (outside your direct control) that does not implement Serializable. You need to mark such a field transient, and figure out how to work around it. Any data that is redundant in some way, that can be derived from other values or looked up from some other resource, is a candidate for transient - especially anything that is implemented to be lazily instantiated.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been working in Java for a couple of years. Never used serialization till date. I think it used for very specific purposes and not by many programmers. Correct me if this sounds not common to you folks?
 
Mike Simmons
Master Rancher
Posts: 4032
54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that's probably fairly common. It depends on what technology stack you're working with for a given company or project - it's definitely possible to go years without ever using it (or at least, without being aware of it). It's also very possible to use it every day. Many traditional uses of serialization have been replaced by alternate forms of serialization, e.g. using JAXB to convert to an XML representation.
 
keiwer villabona ruiz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
may be that I wrote the question wrong.

serialize only the necessary.

thank you (Anayonkar Shivalkar)
 
Freidrick Essamburger
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mark for the information. Its quite possible that I might go for a few more years without using transient. It might be my misfortune or just that ignorance is bliss.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic