ObjectInputStream会阻塞程序,直到对应的ObjectOutputStream准备好
官方API解释:
Creates an ObjectInputStream that reads from the specified InputStream.
A serialization stream header is read from the stream and verified.
This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.
例如:在Socket中使用时,要注意先后顺序
//客户端发起连接
Sockets = new Socket(serverHost,serverPort);
//注意输入输出流的获取顺序
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
本文探讨了ObjectInputStream的工作原理,特别是在与ObjectOutputStream交互时如何阻塞程序直至对方准备就绪。通过Socket通信实例,说明了正确处理输入输出流顺序的重要性。
1086

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



