1. ObjectInputStream與ObjectOutputStream的順序問題 在網絡通訊中,主機與客戶端若使用ObjectInputStream與ObjectOutputStream建立對象通訊,必須注重聲明此兩個對象的順序。 如: 主機端先建立ObjectInputStream后建立ObjectOutputStream,則對應地客戶端要先建立ObjectOutputStream后建立ObjectInputStream,否則會造成兩方互相等待數據而導致死鎖。 原因是建立ObjectInputStream對象是需要先接收一定的header數據,接收到這些數據之前會處于阻塞狀態。以下為java 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.