Socket / writeObject / NotSerializableException question

Discussion in 'Java' started by JMC, Apr 7, 2004.

  1. JMC

    JMC Guest

    Suppose a stream socket connection exists between P[roducer] and
    C[onsumer], where P has an ObjectOutputStream on the socket and C has
    an ObjectInputStream.

    Then if P makes a sequence of OOS.writeXxxx calls, and these are not
    matched exactly in sequence by OIS.readXxxx calls by C, then C will of
    course get out of step and throw an exception, for example
    OptionalDataException.

    However, if P only makes OOS.writeObject calls, and C only makes
    OIS.readObject calls, then they will stay in step as long as
    OOS.writeObject does not throw a NotSerializableException.

    But what if one of P's calls to OOS.writeObject does throw a
    NotSerializableException, e.g. because some sub-sub-object deep in the
    argument's graph is not serialisable? Then C's corresponding
    OIS.readObject will get some sort of "malformed" object (or perhaps
    null).

    But then say P's next call to OOS.writeObject does not raise the
    exception. Is it guaranteed that C will stay in step, and successfully
    read the object? Or is it the case that sometimes P and C will need to
    reset their connection to get back in step when P gets a
    NotSerializableException?
    JMC, Apr 7, 2004
    #1
    1. Advertising

  2. JMC

    Roedy Green Guest

    On 7 Apr 2004 05:01:35 -0700, (JMC) wrote or
    quoted :

    >But then say P's next call to OOS.writeObject does not raise the
    >exception. Is it guaranteed that C will stay in step, and successfully
    >read the object? Or is it the case that sometimes P and C will need to
    >reset their connection to get back in step when P gets a
    >NotSerializableException?


    When you write an object, it is a blob consisting of the object and
    its dependents. If something goes wrong with the read, the stream
    will be sitting at the end of the blob ready to try the next object.

    I would think that if one of the subobjects was faulty, you would have
    a half read tree of objects in RAM, but without a master object to
    point to them, they would soon be garbage collected.

    It should not be hard to try an experiment to ensure it can stay in
    sync. Just leave out one of the classes from the receiver.

    http://mindprod.com/jgloss/fileio.html for sample code.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Apr 7, 2004
    #2
    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. JCM
    Replies:
    1
    Views:
    457
    John C. Bollinger
    Aug 11, 2003
  2. Shannon
    Replies:
    3
    Views:
    22,058
    Shannon
    Jan 9, 2004
  3. Shin
    Replies:
    7
    Views:
    2,679
    Thomas Hawtin
    Aug 3, 2005
  4. 6e
    Replies:
    3
    Views:
    977
    Roedy Green
    Nov 10, 2005
  5. Netlopa
    Replies:
    2
    Views:
    1,998
    roedy
    Jun 4, 2009
Loading...

Share This Page