从套接字等待输入时阻止停止/中断线程 [英] Stop/Interrupt threads blocked on waiting input from socket

查看:98
本文介绍了从套接字等待输入时阻止停止/中断线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我需要一种方法来阻止或中断被套接字输入阻塞的线程。

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

推荐答案

Thread.interrupt( )应该是您正在寻找的方法。
确保您的输入访问方法还检查InterruptedException和ClosedByInterruptException。

Thread.interrupt() should be the method you're looking for. Be sure that your input-accessing methods also check for InterruptedException and ClosedByInterruptException.

还要查看相应的 Sun并发教程中的页面,正如另一个解决方案所示。

Also look at the corresponding page in the Sun Concurrency Tutorial, as another solution suggests.

这篇关于从套接字等待输入时阻止停止/中断线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆