English 中文(简体)
贾瓦邦因hang制 process而中断铺
原标题:Interrupting Thread in Java for hanged process

如果是这样的话:

Thread t = new Thread(myThread);
t.start();

private static Runnable myThread = new Runnable() {
    public void run() {
        try{
            String line=null;
            while ((line = eStream.readLine()) != null){
                //do something
            }
         }
         catch (Exception e){}
    }
};  

现在,路边发生的情况有时是readLine()被hang死,因为它期待外部进程提供投入。 因此,在这种情况下,我试图做的是设置一个时间,如果时间到期,即<代码>与t.interrupt(>);在座。

现在,在审判组之后,我试图收集<条码>不间断的Exception,即汇编时间错误。 在这种情形下,有人能告诉我,如何追赶中断的例外情况?

谢谢。

最佳回答

断断线打断了“Line()”电话。 你们必须结束这项工作。

You are catching the InterruptedException already (and ignoring it) with this line

catch (Exception e){}

工作成绩

line = eStream.readLine().toString()

当你到案尾的时候,它将扔下Null PointerException。 删除<代码>。

问题回答

http://docs.oracle.com/javase/1.4.2/docs/api/java/langruptedException.html InterruptedException:

Thrown when a thread is waiting, sleeping, or otherwise paused for a long time and another thread interrupts it using the interrupt method in class Thread.

我怀疑你对以下网站的兴趣::

Signals that an I/O operation has been interrupted. An InterruptedIOException is thrown to indicate that an input or output transfer has been terminated because the thread performing it was interrupted.

I would check out this JavaSpecialists newsletter on cleanly shuttin gdown threads and particularly the subsection What about threads blocked on IO? which covers this area in some detail.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签