Stop/Interrupt threads blocked on waiting input from socket

后端 未结 6 1833
自闭症患者
自闭症患者 2021-01-04 04:12

As the title says I need a way to stop or interrupt a thread that is blocked waiting on an input from the socket.

6条回答
  •  青春惊慌失措
    2021-01-04 04:56

    You could simply close() the IO stream/socket from another thread. Then, you could check on a volatile boolean field if the resulting IOException is due the close or something else. I think the close might result in an java.net.SocketException: Socket closed exception.

提交回复
热议问题