Is setting a timeout on ObjectInputStream.readObject() safe?

后端 未结 2 1241
忘掉有多难
忘掉有多难 2021-01-14 17:45

I have an ObjectInputStream connected to an ObjectOutputStream through a socket, and I\'ve been using Socket.setSoTimeout() to make

2条回答
  •  爱一瞬间的悲伤
    2021-01-14 18:26

    If you set the timeout shorter than the normal delays which might occur in reading a stream, you can expect the timeout to be in effect when the stream is still properly active.

    100 ms seems like a long time, but not if there's disk or network traffic involved. Try timing out on something ridiculous, like a second.

提交回复
热议问题