gpt4 book ai didi

java - 我能否唤醒因调用 DatagramSocket.receive() 而阻塞的线程?

转载 作者:搜寻专家 更新时间:2023-10-31 20:06:30 26 4
gpt4 key购买 nike

我有一个阻塞在 UDP 数据包上的线程,我需要能够告诉它忘记那个数据包并做其他事情,所有这些都在接收超时发生之前。有什么办法吗?

最佳答案

使用 DatagramChannel 读取您的 UDP 数据包,并中断读取线程。根据 Thread.interrupt(和 DatagramChannel)的文档,读取操作将抛出 ClosedByInterruptException。

关于java - 我能否唤醒因调用 DatagramSocket.receive() 而阻塞的线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5134631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com