I'm just starting out with Java serialization, and I'm not clear on how you are supposed to get objects from a source in a scenario with non-blocking I/O .
All the documentation I can find suggests using ObjectInputStream is the proper way to read in serialized objects. However, as I mentioned I'm using java.nio and performing non-blocking operations. If readObject() will block until a new object is available, this can't help me
Summary .. How do you do serialization when working with Java NIO?
Wrap the serialized instances in a protocol that reports a payload length, and the payload is the instance in question. Then once you know you have a segment that represents a complete instance you can use ObjectInputStream safely knowing it won't block.
Protocol like this First 32 bits: Payload length Payload length bits: Serialized data
Sometimes I amaze even myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With