调用线程的interrupt()会发生什么? [英] What happens when you invoke a thread's interrupt()?

查看:186
本文介绍了调用线程的interrupt()会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道会发生什么

  1. 什么时候睡觉?
  2. 运行时,即正在执行给定的任务.

提前谢谢.

推荐答案

从您先前的问题来看,我认为您对Java的行为感兴趣.

Judging by your previous questions, I assume you are interested in Java's behavior.

在Java中,如果线程当前正在阻塞,则将抛出InterruptedException.如果线程没有阻塞,则不会引发异常.

In Java, an InterruptedException will be thrown if the thread is currently blocking. If the thread is not blocking, the exception will not be thrown.

有关更多信息,请参见此处:
JavaDocs

For more information, look here:
JavaDocs

对于.NET语言,如果线程当前正在阻塞,则将抛出ThreadInterruptedException.如果线程没有阻塞,则在线程阻塞之前不会引发异常.

For .NET languages, a ThreadInterruptedException will be thrown if the thread is currently blocking. If the thread isn't blocking the exception will not be thrown until the thread blocks.

请用您想要的答案的语言标记您的问题.

Please tag your question with the language you want an answer for.

这篇关于调用线程的interrupt()会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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