谁打断了我的线程? [英] Who interrupts my thread?
问题描述
我理解InterruptedException的作用以及它被抛出的原因。但是在我的应用程序中,我在等待我的应用程序只知道的线程上的 SwingUtilities.invokeAndWait()
时得到它,而我的应用程序从不调用任何线程上的Thread.interrupt()
,它也永远不会将线程的引用传递给任何人。
I understand what an InterruptedException does and why it is thrown. However in my application I get it when waiting for SwingUtilities.invokeAndWait()
on a thread that is only known by my application, and my application never calls Thread.interrupt()
on any thread, also it never passes the reference of the thread on to anyone.
所以我的问题是:谁打断了我的帖子?
So my question is: Who interrupts my thread?
有什么方法可以告诉我吗?是否有理由说InterruptedException不包含请求中断的Thread的名称?
Is there any way to tell? Is there a reason why the InterruptedException doesn't contain the name of the Thread that requests the interrupt?
我读到它可能是一个框架或库来执行此操作,我们使用以下内容,但我想不出他们打断我的线程的原因:
I read that it could be a framework or library that does this, we use the following, but I can't think of reason for them to interrupt my thread:
- Hibernate
- Spring
- Log4J
- Mysql连接器
- Hibernate
- Spring
- Log4J
- Mysql connector
推荐答案
如果可能,您可以扩展 Thread
并覆盖中断()
此线程打印堆栈跟踪或抛出不支持的操作异常的方法。
If possible, you could extend Thread
and overwrite the interrupt()
method for this thread to print a stacktrace or throw an unsupported operation exception.
您还可以使用扩展的 Thread
类来存储对中断线程的引用,并在捕获后读取它中断的异常。
You could also use the extended Thread
class to store a reference to the interrupting thread and read it once you catch the interrupted exception.
这篇关于谁打断了我的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!