InterruptedException的原因 [英] The Cause of InterruptedException

查看:78
本文介绍了InterruptedException的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从J2me文档中我们知道:

From J2me doc we know that:

java.lang.InterruptedException当线程在等待,睡眠或以其他方式暂停很长时间,而另一个线程中断它时,抛出该异常.

java.lang.InterruptedException Thrown when a thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it.

问题是,如果从一个线程调用另一个线程的Thread.Interupt(),而另一个线程的Run()方法在InputStream.Read(char [] buf)上等待,是否有可能获得此类异常?

The question is if it's posible to get such exception if from one thread i call Thread.Interupt() for other thread where Run() method of other thread waiting on InputStream.Read(char[]buf) ?

推荐答案

响应线程中断的阻塞读取行为实际上是不确定的.有关详细信息,请参见此长期存在的错误.简而言之,有时您会得到EOF,有时会得到IOException.

The behavior of blocking read in response to thread interrupt is, in fact, undefined. See this long-standing bug for details. The short of it is that sometimes you get EOF, sometimes you get IOException.

这篇关于InterruptedException的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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