I’m building a client-server application.
The server keeps a list of objects:
LinkedList<MyObject> objects;
Every time an object is added or deleted, the clients should know this.
They joined the multicast group already.
What is the best way to keep them notified of changes?
Should I make a class that extends LinkedList and Implement it with Serializable?
Multi-casting the updated list each time it changes is certainly simple, but there may be issues.
If the list gets large or the updates are frequent, scalability may be a concern. Consider sending the changes to the list as “deltas” rather than sending the entire list each time.
Serialization using
ObjectOutputStreamcan be expensive, though you can improve the performance by writing customreadObjectandwriteObjectmethods. (Serialization of lists is already optimized …)You don’t need to subclass
LinkedListto do this. It is alreadySerializable.You most likely need to synchronize the list structure to avoid race conditions and mayhem, but that will create a potential bottleneck. Consider replacing the
Listwith a concurrent implementation ofQueueorDeque.