Java Swing : GUI frozen - jstack interpretation

喜你入骨 提交于 2019-11-29 14:54:10
trashgod

AWT-EventQueue-0 is your event dispatch thread, and it is indeed blocked reading from a serial port via RXTX a socket via hsqldb. You should use SwingWorker, as suggested by @Kumar. Examples may be found here and here. I found it helpful to examine such examples in a profiler for study.

Thread-6 and Thread-7 appear to belong to your application as instances of Threads.ThreadHorloge in posO2. Regarding thread names:

Every thread has a name for identification purposes. More than one thread may have the same name. If a name is not specified when a thread is created, a new name is generated for it.

Note that SwingWorker and Executors typically include the text pool-n, where n is a sequence number.

Addendum: My EDT is in a RUNNABLE state, so from the code I pasted where do you figure out that it's blocked; and where do you find that the reading via RXTX is the blocking cause?

Sorry, my mistake; corrected above. The EDT isn't BLOCKED in the Thread.STATE sense of waiting for a monitor lock; it's blocked in the sense that it's waiting for the database to respond, at least long enough to be seen atop the call stack when you send the -QUIT signal. Neither serial nor network operations should be scheduled on the EDT.

Kumar Vivek Mitra

One very basic rule:

  • Keep the UI work on the UI thread, and the Non-UI work on the Non-UI thread.

This way we can keep the GUI interactive and responsive.

  • In Java Event Dispatcher Thread (EDT) is the UI thread, main() method in Java GUI application is not long lived, so after scheduling the work of GUI construction in the Event Dispatcher Queue it quits and then it's EDT that handles the GUI.

  • Either use Thread to do the Long Non-UI processing work, or use SwingWorker, this is provided in java to do a seamless synchronization between the UI and Non-UI work......

This thread is the one that's started from the Event Queue

"AWT-EventQueue-0" prio=6 tid=0x02b6e000 nid=0xcbc runnable [0x033fe000] java.lang.Thread.State: RUNNABLE

You can tell because at the very end of the stack trace of this tread, it's started by the EventDispatchThread:

at java.awt.EventDispatchThread.run(Unknown Source)

As far as your question about "What's the difference between Thread 6 and Thread 7", I don't have a direct answer for you, but I'm thinking most of these threads were created by your profiler (as so what you're seeing is threads that it spun up). Could be wrong on that though. I can't find anything on the Threads.ThreadHorloge class it's referencing offhand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!