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());