Hi all,
I am developing a Client/Server java application, where CSMessage is sent through socket.
CSMessage has some data like String type and HashMap<String, String> type.
the Client send message:
private ObjectInputStream in; private ObjectOutputStream out; out = new ObjectOutputStream(socket.getOutputStream()); in = new ObjectInputStream(socket.getInputStream()); try { out.writeObject(message); out.flush(); } catch (IOException e) { //... }
and the following is the code snippet of the Server side:
in = new ObjectInputStream(socket.getInputStream()); out = new ObjectOutputStream(socket.getOutputStream()); CSMessage fromClient = null; try { fromClient = (CSMessage) in.readObject(); } catch (ClassNotFoundException e) { //..... } catch (IOException e) { //.... } }
this code works fine for more than a year untill recently exception occurred intermittently:
Exception in thread "Thread-72" java.lang.IllegalStateException: unread block data
at java.io.ObjectInputStream$BlockDataInputStream.set BlockDataMode(ObjectInputStream.java:2393)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1378)
at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1963)
at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1430)
at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)
sometimes we got another alternative exception :
Exception in thread "Thread-58" java.lang.ClassCastException: cannot assign instance of com.ictbox.acc.utils.msg.CSMessage to field com.ictbox.acc.utils.msg.CSMessage.command of type java.lang.String in instance of com.ictbox.acc.utils.msg.CSMessage
at java.io.ObjectStreamClass$FieldReflector.setObjFie ldValues(ObjectStreamClass.java:2056)
at java.io.ObjectStreamClass.setObjFieldValues(Object StreamClass.java:1229)
at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1969)
at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1311)
at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)
or
Exception in thread "Thread-26" java.lang.ClassCastException: java.lang.String cannot be cast to java.io.ObjectStreamClass
at java.io.ObjectInputStream.readClassDesc(ObjectInpu tStream.java:1507)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
at java.io.ObjectInputStream.defaultReadFields(Object InputStream.java:1963)
at java.io.ObjectInputStream.readSerialData(ObjectInp utStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(Objec tInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputS tream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputSt ream.java:368)
at com.ictbox.acc.toolbarserver.AgentbarServerRequest Handler.handleRequest(AgentbarServerRequestHandler .java:1326)
at com.ictbox.acc.toolbarserver.RequestThread.run(Req uestThread.java:189)
When this happen, the only way to make the system to work is to kill the process and restart it, that's bad!
How to solve it? Any ideas are highly apprieciated.
yhqian99