Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Serialization Problems and books on serialization?

Reply
Thread Tools

Serialization Problems and books on serialization?

 
 
sinleeh@hotmail.com
Guest
Posts: n/a
 
      12-09-2004
I was trying to do serialization but have problems writing object with
ObjectOutputStream.writeObject().

The problem is that ObjectOutputStream.writeObject() sometimes fails
the serialize object mysteriously. It serialize objectA by itself OK,
but when you use objectA as data member of objectB and serialize
objectB, it fails.

My latest problem is about serializing a java.util.List of String. When
the said list is a data member in objectA, serialization OK. However,
when I put objectA inside objectB and serialize objectB, serialization
failed unless I remove the List of String in objectA.

The problem is not unique to list of string and it is known to happen
on other objects.

I am pretty sure it is something I did but just cannot figure out how.
Can anyone point out how to solve this problem or a workaround?

Also, can someone recommend a book on serialization.

Many thanks in advance.

Sinlee Huang.
P.S. Please reply to this newsgroup only coz I do not check the hotmail
account I am using

 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      12-09-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I was trying to do serialization but have problems writing object with
> ObjectOutputStream.writeObject().
>
> The problem is that ObjectOutputStream.writeObject() sometimes fails
> the serialize object mysteriously. It serialize objectA by itself OK,
> but when you use objectA as data member of objectB and serialize
> objectB, it fails.


How exactly does it "fail"?
 
Reply With Quote
 
 
 
 
sinleeh@hotmail.com
Guest
Posts: n/a
 
      12-09-2004
> How exactly does it "fail"?

That's the strange thing. The function call never return. In other
words, it hangs the program. There are no significant CPU activity.

The following is the code sniplet for serialization used. model1 is the
objectB on previous message.

PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(model1);

It does not like the last line.

Just in case it's relevent, I am using Sun's java SDK 1.4.2
Thank you in advance
Sinlee

 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      12-09-2004
(E-Mail Removed) wrote:

>>How exactly does it "fail"?

>
>
> That's the strange thing. The function call never return. In other
> words, it hangs the program. There are no significant CPU activity.
>
> The following is the code sniplet for serialization used. model1 is the
> objectB on previous message.
>
> PipedOutputStream out = new PipedOutputStream();
> PipedInputStream in = new PipedInputStream(out);
> ObjectOutputStream oos = new ObjectOutputStream(out);
> oos.writeObject(model1);
>
> It does not like the last line.


I suspect that it has nothing to do with serialization at all and
that your write call just blocks because the buffer of the PipedInputStream
is full. You have to read it in a different thrad. If that's not it,
make an SSCCE: http://www.physci.org/codes/sscce.jsp
 
Reply With Quote
 
sinleeh@hotmail.com
Guest
Posts: n/a
 
      12-09-2004
Many Thanks for the info. It is a new lead for me. I will try to
investigate the buffer issue. Will probably takes some time. I will of
course report back when its done.

Best regards,
Sinlee

 
Reply With Quote
 
sinleeh@hotmail.com
Guest
Posts: n/a
 
      12-09-2004
I should add that what you suggests make sense because the problematic
serialization occurs generally on larger composite objects.

Your reply had lead me to think about how I serialize very large
object. upon inspection of the code, I see that I actually use
ByteArrayOutputStream and ByteArrayInputStream for very large object.
Will replace Piped*Stream with them and see what happens.
Best regards,
Sinlee

 
Reply With Quote
 
Sudsy
Guest
Posts: n/a
 
      12-09-2004
(E-Mail Removed) wrote:
>>How exactly does it "fail"?

>
>
> That's the strange thing. The function call never return. In other
> words, it hangs the program. There are no significant CPU activity.
>
> The following is the code sniplet for serialization used. model1 is the
> objectB on previous message.
>
> PipedOutputStream out = new PipedOutputStream();
> PipedInputStream in = new PipedInputStream(out);
> ObjectOutputStream oos = new ObjectOutputStream(out);
> oos.writeObject(model1);
>
> It does not like the last line.


Since I don't see any code (should be a separate thread) reading the
pipe, I'd guess that you're filling up the pipe. The capacity is not
infinite and you're probably blocking on the write.

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.

 
Reply With Quote
 
sinleeh@hotmail.com
Guest
Posts: n/a
 
      12-10-2004
Dear Sudsy, Michael,

Indeed as both of you spotted, my problem is with buffer. I changed to
ByteArrayStreams (whose buffers can grow with data) and everything go
away.

Many thanks for your help.

Best regards,
sinlee

 
Reply With Quote
 
deadsea
Guest
Posts: n/a
 
      01-02-2005
You might want to look at my article on converting a java ouptstream to
an inputstream:
http://ostermiller.org/convert_java_...putstream.html

It discusses several methods for avoiding filling up the buffer of a
piped stream.

Stephen

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to move from java object serialization to xml serialization? Dimitri Ognibene Java 4 09-02-2006 07:32 AM
Object serialization XML vs java serialization plasticfloor@gmail.com Java 3 06-14-2006 03:45 AM
Books, books, books: best reference texts for Verilog and VHDL HDL Book Seller VHDL 0 12-01-2004 02:26 AM
Books, Books, Books... C++ 3 09-19-2004 10:11 PM
avoiding XML serialization, different WSDL generation, soap serialization Ramunas Urbonas ASP .Net Web Services 1 07-27-2004 09:57 PM



Advertisments