package com.java.util.concurrent; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class Test1 { public static void main(String[] args) throws Exception { ExecutorService exeService = Executors.newFixedThreadPool(1); Future<Thread> future = exeService.submit(new CallableC<CallObj>(new CallObj())); // exeService.submit(new CallableC<CallObj>(new CallObj())); blocking quene Thread s = future.get();// get() is blocking System.out.println(s); System.out.println(s.isInterrupted()); } static class CallObj{ @Override public String toString() { return System.currentTimeMillis()+""; } } static class CallableC<V> implements Callable{ private V obj ; public CallableC(V o) { obj = o; } public Thread call() throws Exception { System.out.println("start....."); int i = 0; try { while (true) { call(obj); Thread.sleep(1000);// in sleep(),weather interrupted; i=7,currentThread is interrupted i++; if(i>5)// 7 times ; i=6 currentThread.interrupt() Thread.currentThread().interrupt(); } } catch (Exception e) { e.printStackTrace(); }finally{ System.out.println("done....."); } return Thread.currentThread(); } public String call(V arg){ System.out.println(Thread.currentThread().getName()); return null; } } }
中断特点:
1. 只能中断线程阻塞 时
2. 中断不影响thread代码逻辑,只是一个标志位的改变和中断异常的表示
Thread.currentThread().interrupt(); 会把Thread,中断标志位 标志为 true,
Thread.sleep() ; 方法内部Thread会判断当前线程的中断标志位,为true,则抛出中断异常
Thread被中断(这里(上面的代码)是指抛出中断异常了),thread仍继续执行,如果没有使用中断标志位进行其它的逻辑处理,中断就没有意义
相关推荐
03_AURIX Interrupt Router.pdf
switch_counter_interrupt_TivaWare.c
IAR环境下AT91SAM7S64开发板例程(实现中断功能)
ARM UART中断处理啊试验AR M UART中断处理啊试验
Hw-interrupt 8051 how to generate external interrupt in 8051
program for 8051 software interrupt
MSP430,常用中断,非常实用的好资料,特别适合初学者。
ACPI PCI Interrupt Routing
Interrupt Example in MPLABX XC8 Compiler
adc采集中断和lcd显示,测试效果较好
ARM7-LPC2148的外部中断源码。。。
基于s3c2440的内核adc驱动程序,中断模式~aaaaaaaaaaaaaa
switch_delay_interrupt.c
adu7026的定时中断程序,适合于初学者进行aduc7026的开发和应用
LPC2368 GPIO_INT外中断测试程序,按复位如果8个LED是全亮的。然后按一下中断按键INT键。如果按下触发INT0中断服务程序,会将8个LED熄灭。
stm32_Lesson2_TIM_INTERRUPT_stm32_源码.zip
飞思卡尔HCS12单片机定时器中断调试程序 适合飞思卡尔单片机初学者使用
linux 驱动中编程的核心内容,中断,这会和arm7中的中断很好的结合起来。
单片机外部中断的典型应用,proteus仿真,程序,原理图全套。
evm5510利用DMA及中断来测试MCbsp多通道传输数据的测试程序