Reducing the size of a serialized object.

A

Andoni

Hello,

I have an RMI server that takes certain actions on a bean that is passed to
it. Because a lot of beans are being sent over the wire to the RMI server
every day I want to try to keep down the size of the serialized bean.

I am not using a web server or class server to download stubs but instead I
just put a copy of all classes (and stubs) on each machine at deployment
time so that the only thing that needs to be passed over the wire is the
data in the bean. Now I have a decision to make. I want to add 3 big methods
to the bean because they should be part of this bean for the program to be
very OO compliant. I want to know, will this increase the amount of data
that has to be sent over the wire?

In short: are the methods of a serialized bean also serialized in some way
or is it only the data contained in the object or is it the data and the
method signatures?

Thanks in advance for any and all help,

Andoni.
 
A

Andoni

Having done a little research on the web and found lots of pages on Java
Serialization I find that the best place to look is the JavaDoc's
introduction to the: ObjectOutputStream.

From lines like:

" The default serialization mechanism for an object writes the class of the
object, the class signature, and the values of all non-transient and
non-static fields. "

I am assuming that when it says "writes the class of the object" that it
does not write the .class file but rather just a string saying what the
class is called.

This would mean that my adding 3 big methods would only add 3 more strings
(their signatures) to the traffic on the line. This I can live with.

Thanks,

Andoni.
 
I

Ingo R. Homann

Hi Andoni,
From lines like:

" The default serialization mechanism for an object writes the class of the
object, the class signature, and the values of all non-transient and
non-static fields. "

I am assuming that when it says "writes the class of the object" that it
does not write the .class file but rather just a string saying what the
class is called.

Better than "assuming" is looking in the spec or the source. When I
understand the source corrctly, I assume (;-) that the class name and
the serialVersionUID is written.
This would mean that my adding 3 big methods would only add 3 more strings
(their signatures) to the traffic on the line.

No! This would mean that adding three methods would change nothing
(except the serialVersionUID, I hope).
This I can live with.
OK!

Thanks,

Andoni.

Ciao,
Ingo
 
J

jan V

This would mean that my adding 3 big methods would only add 3 more
strings
No! This would mean that adding three methods would change nothing
(except the serialVersionUID, I hope).

That's correct. Adding methods won't alter the size of the serialized
object.

See Chapter 11 of "Mastering JavaBeans"
http://ccd.uab.es/~srobles/manuals/JavaBeans/

for a detailed text on what goes on behind the scenes.
 
A

Andoni

Thank you both for that info.

I have a pretty slick Class now instead of passing a million parameters to a
static method in another class.

Andoni.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top