If I have multiple Java threads writing to the same Socket instance simultaneously, will that affect the integrity of the objects that are read from the same socket? I.e., whether the contents of the objects will be messed up etc. It's fine for the ordering of objects to be random.
解决方案
In general, there are no guarantees. Bits of different objects could well end up getting interleaved on the wire, rendering the result indecipherable. Therefore, you need to provide external synchronization.
当多个Java线程同时写入同一个Socket实例时,可能会导致对象内容交错,破坏读取的完整性。为避免这种情况,需要外部同步机制来确保数据的正确性。线程安全对于网络通信至关重要,不加控制的并发写入会使得对象在传输过程中变得无法解析。
299

被折叠的 条评论
为什么被折叠?



