谁打扰了我的话题?

发布于 2024-08-25 08:32:21 字数 422 浏览 3 评论 0原文

我了解 InterruptedException 的作用以及抛出它的原因。然而,在我的应用程序中,当我在只有我的应用程序知道的线程上等待 SwingUtilities.invokeAndWait() 时,我得到了它,并且我的应用程序从不调用 Thread.interrupt()在任何线程上,它也不会将该线程的引用传递给任何人。

所以我的问题是:谁中断了我的线程?

有什么办法可以告诉吗? InterruptedException 不包含请求中断的线程的名称是否有原因?

我读到它可能是执行此操作的框架或库,我们使用以下内容,但我想不出他们中断我的线程的原因:

  • Hibernate
  • Spring
  • Log4J
  • Mysql 连接器

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?

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 connector

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

病毒体 2024-09-01 08:32:21

如果可能,您可以扩展 Thread 并覆盖该线程的 interrupt() 方法,以打印堆栈跟踪或引发不受支持的操作异常。

您还可以使用扩展的 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.

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.

嘴硬脾气大 2024-09-01 08:32:21

一般来说,如果您想知道谁在做某事,请附加一个调试器,放置一个断点,然后就可以了。无需猜测是否可以重现它!

在这种情况下,您可以在 Thread.interrupt() 处放置断点。如果还有其他线程也被中断(因此您在断点上出现“误报”),您可以添加断点条件(大多数 IDE 允许您轻松执行此操作),例如通过检查线程的名称。

In general, if you want to know who is doing something, attach a debugger, put a breakpoint, and there you go. No need for guessing if you can reproduce it!

In this case, you can put a breakpoint at Thread.interrupt(). If there are other threads that are being interrupted too (so you have "false positive" hits on the breakpoint), you could add a breakpoint condition (most IDE's allow you to do that easily), for example by checking the name of the thread.

千纸鹤带着心事 2024-09-01 08:32:21

这里有一些奇怪的事情。

来自 invokeAndWait,抛出 InterruptedException

如果我们在等待事件调度线程完成执行 doRun.run() 时被中断

您是否尝试过查看 EDT 中执行的代码是否发送任何异常?或者执行 EDT 中的代码尝试修改该线程的一些变量(我知道这个术语在 java 语言中不是“正统”,但我希望你明白我的意思:任何暗示同步、等待、加入等的代码)

There is something strange here.

From the javadoc of invokeAndWait, an InterruptedException is thrown

if we're interrupted while waiting for the event dispatching thread to finish excecuting doRun.run()

Have you tried to see if the code executed in the EDT sends any exception ? Or do the code in that EDT tries to modify some of this thread's variables (I know this term is not "orthodox" in java language, but I hope you see what I mean : any code implying synchronized, wait, join, ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文