`

interrupt

阅读更多

1) Each thread has a boolean interrupted status.

 

2) 3 interrupt related methods defined in Thread class

 

public class Thread

{

    public void interrupt() {...} // interrupts the target thread

 

    public boolean isInterrupted() {...} //return the interrupted status of the target thread.

 

     //clear the interrupted status of the current thread, and returns its previous value.

     //This is the 1st way to clear the interrupted status

    public static boolean interrupted() {...}

}

 

3) Another way the clear the interrupted status is:

When the thread is in blocked status, if you call interrupt() on it, the thread will automatically go to Catch(InterruptedException e){...} block. As soon as the exception is thrown out, the interrupted status will be cleared.

 

4) interrupt() method acutally does just one thing --- set interrupted status to true. Nothing else. From this point of view, it only makes sense when the thread is monitoring the interrupted status.

The thread will monitor the interrupted status only under 1 situation --- the thread is in blocked status which is wrapped with catch(InterruptedException e){}

1) thread.sleeping()

2) object.waiting()

3) BlockedQueue operations

4) Lock.lockInteruptibly()

 

What I want to say is, very likely, interrupt() method doesn't work for some thread, it means those threads are not interruptable.

 

So, just one sentence to summary,

 

If the current line of code is monitored by InterruptedException, then, if you interrupt it at the time or before that, it will work. Otherwise, just everthing in vain---setting interrupted status to true means nothing!

分享到:
评论

相关推荐

    Interrupt.X_interrupt_

    在嵌入式系统开发中,中断(Interrupt)是硬件与软件之间进行通信的重要机制,它使得微控制器能够及时响应外部事件,而无需持续轮询。本文将深入探讨使用MPLABX集成开发环境和XC8编译器进行中断处理的例子。 标题...

    解释 void timer0() interrupt 1 using 2

    ### 解释 void timer0() interrupt 1 using 2 在探讨`void timer0() interrupt 1 using 2`这一表达式之前,我们首先需要理解它所处的上下文——80C51单片机系统及其编程环境。80C51是一款广泛应用于嵌入式系统的微...

    com interrupt void interrupt 4 using 3

    在IT领域,"com interrupt void interrupt 4 using 3" 这个描述涉及到的是中断服务子程序(Interrupt Service Routine, ISR),这是在微处理器系统中处理外部硬件事件的一种机制。这里的“com”可能指的是串行通信...

    ARM Generic Interrupt Spec

    ### ARM Generic Interrupt Controller (GIC) Architecture Specification #### 概述 ARM Generic Interrupt Controller (GIC) 是一种中断控制器架构规范,旨在为基于ARM架构的操作系统提供通用且灵活的中断管理...

    Interrupt in Linux(硬件篇).pdf

    早期的PC系统采用传统的可编程中断控制器(PIC, Programmable Interrupt Controller)来管理中断请求。在最初的IBM PC设计中,有两个8259A PIC芯片共同工作,负责处理中断请求。 - **主PIC**: 负责管理IRQ0至IRQ7共8...

    Polyspace不认识Interrupt,肿么办?

    ### Polyspace与中断处理:让Polyspace认识Interrupt #### 一、引言 在嵌入式系统开发过程中,中断处理是不可或缺的一部分。中断可以让系统在特定条件下响应外部事件,从而实现高效的实时处理能力。然而,在进行...

    Ralf Brown's Interrupt List

    《Ralf Brown's Interrupt List》是计算机领域内一本非常重要的参考资源,主要涵盖了微处理器和其他硬件设备中断的详细信息。这个列表由Ralf Brown维护,是程序员、系统工程师和硬件爱好者在处理中断相关问题时不可...

    interrupt中断

    处理器响应中断后,会保存当前任务的状态,跳转到预先定义的中断服务程序(ISR,Interrupt Service Routine)执行相应的操作,处理完事件后再恢复先前的任务,这就是中断的上下文切换。 在基于DSP的系统中,中断...

    电子-7interrupt.pdf

    文档首先介绍了在nRF51822中引入的Task和Event机制,以及它们与Interrupt(中断)的关系。接着详细阐述了中断的概念、中断的触发机制、中断源代码的编写、以及如何通过代码样例来实现中断接收。以下详细解释了文档中...

    ARM Generic Interrupt Controller Architecture Specification

    文档提供了ARM® Generic Interrupt Controller的架构规范,介绍了GIC架构3.0和4.0版本的详细信息,其中包含了一些在先前版本2.0中已经发布的资料。此外,文档还涉及到版权和知识产权的声明,明确指出该文档受版权...

    Ralf Brown's Interrupt List(中断大全)

    《Ralf Brown's Interrupt List》是DOS操作系统中不可或缺的一个技术资源,由Ralf Brown编纂,详尽地列举了DOS以及IBM PC兼容机上的中断服务,包括BIOS(基本输入输出系统)和DOS中断。这个列表是程序员、系统开发者...

    interrupt_asm.zip

    程序名称:interrupt.asm 程序说明:74HC595驱动数码管动态显示例,通过按键触发外部中断,P3.2进行计数,P3.3清零,实验箱上完成 算法说明:由两片74HC595芯片分别驱动段和位,数码管动态扫描显示:修改延时子...

    Detection of Excessive Interrupt Disablement

    Detection of Excessive Interrupt Disablement - a new feature which can detect a period of excessive interrupt disablement on a CPU, and create an error log record to report it. This allows you to know...

    ARM Generic Interrupt Controller(ARM GIC控制器)V2.0.pdf

    ARM Generic Interrupt Controller (ARM GIC控制器)V2.0 ARM Generic Interrupt Controller (ARM GIC控制器)是ARM公司推出的一个通用中断控制器架构规范,用于实现高效的中断处理。该规范旨在提供一个灵活的中断...

    gic600_generic_interrupt_controller_reference_manual.pdf

    《Arm CoreLink GIC-600 Generic Interrupt Controller 技术参考手册》是关于ARMv8架构下中断控制器GIC-600的详细指南,由ARM Limited或其关联公司版权所有。该手册覆盖了从r1p6版本的多个发布迭代,提供了控制器的...

    Interrupt Services DOS, BIOS, EMS and Mouse.pdf

    在计算机科学领域,中断服务程序(Interrupt Service Routines, ISR)是一种特殊类型的程序,它们被设计用于处理来自硬件设备的中断请求。这些请求可能由外部事件触发,如键盘按键、定时器超时或磁盘读写完成等。在...

    Generic Interrupt Controller 2.0

    The Generic Interrupt Controller (GIC) architecture defines: • the architectural requirements for handling all interrupt sources for any processor connected to a GIC • a common interrupt controller ...

    微机接口课程实验interrupt.asm

    微机接口课程实验interrupt.asm

    Open Firmware Recommended Practice: Interrupt Mapping Version 0.9

    ### Open Firmware Recommended Practice: Interrupt Mapping 版本 0.9 #### 1. 概述与背景 在计算机系统中,中断(Interrupt)是硬件设备与操作系统之间进行通信的重要方式之一。当一个设备需要处理紧急任务时,...

Global site tag (gtag.js) - Google Analytics