Serialization Problems and books on serialization?

Discussion in 'Java' started by sinleeh@hotmail.com, Dec 9, 2004.

  1. Guest

    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
    , Dec 9, 2004
    #1
    1. Advertising

  2. 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"?
    Michael Borgwardt, Dec 9, 2004
    #2
    1. Advertising

  3. Guest

    > 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
    , Dec 9, 2004
    #3
  4. 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
    Michael Borgwardt, Dec 9, 2004
    #4
  5. Guest

    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
    , Dec 9, 2004
    #5
  6. Guest

    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
    , Dec 9, 2004
    #6
  7. Sudsy Guest

    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.
    Sudsy, Dec 9, 2004
    #7
  8. Guest

    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
    , Dec 10, 2004
    #8
  9. deadsea Guest

    deadsea, Jan 2, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HDL Book Seller
    Replies:
    0
    Views:
    889
    HDL Book Seller
    Dec 1, 2004
  2. Luis Esteban Valencia

    Design Patterns Books and Best Practices Books.

    Luis Esteban Valencia, Jun 30, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    488
    Joerg Jooss
    Jul 1, 2005
  3. Guest

    Books, Books, Books...

    Guest, Sep 19, 2004, in forum: C++
    Replies:
    3
    Views:
    491
    ÁÍÄÑÅÁÓ ÔÁÓÏÕËÁÓ
    Sep 19, 2004
  4. sloan
    Replies:
    16
    Views:
    832
    Andrus
    Feb 15, 2008
  5. C Books and algorithm books

    , Apr 12, 2008, in forum: C Programming
    Replies:
    22
    Views:
    818
    user923005
    Apr 15, 2008
Loading...

Share This Page