Java Swing : GUI frozen - jstack interpretation

前端 未结 3 1181
再見小時候
再見小時候 2020-12-21 01:42

I have a Gui application in swing that prints a ticket on a serial thermal printer. When i hit the button that launch this action, my GUI is frozen. I think that\'s because

3条回答
  •  伪装坚强ぢ
    2020-12-21 01:57

    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.

提交回复
热议问题