我有一个Gui应用程序,它可以在串行热敏打印机上打印票证。当我点击启动此操作的按钮时,我的GUI被冻结。我认为这是因为代码是在EDT上执行的。我用jstack来确定,但是我不明白下面的结果:
Full thread dump Java HotSpot(TM) Client VM (23.3-b01 mixed mode, sharing):
"Thread-12" prio=6 tid=0x03012000 nid=0xd04 runnable [0x038ef000]
java.lang.Thread.State: RUNNABLE
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
"Thread-6" prio=6 tid=0x0302c400 nid=0x1b0 waiting on condition [0x039ef000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at posO2.Threads.ThreadHorloge.run(ThreadHorloge.java:46)
"Thread-5" prio=6 tid=0x03511c00 nid=0x9e4 waiting on condition [0x0399f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at posO2.Threads.ThreadIgor.run(ThreadIgor.java:29)
"Thread-7" prio=6 tid=0x034b9800 nid=0xb40 waiting on condition [0x0394f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at posO2.Threads.ThreadHorloge.run(ThreadHorloge.java:46)
at java.lang.Thread.run(Unknown Source)
"Thread-4" prio=6 tid=0x0318ec00 nid=0xa08 waiting on condition [0x0323f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at posO2.Threads.ThreadMajProduits.run(ThreadMajProduits.java:49)
"TimerQueue" daemon prio=6 tid=0x03036400 nid=0x9b8 waiting on condition [0x0344
f000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x27e76778> (a java.util.concurrent.locks.Abstra
ctQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject
.await(Unknown Source)
at java.util.concurrent.DelayQueue.take(Unknown Source)
at javax.swing.TimerQueue.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"DestroyJavaVM" prio=6 tid=0x003c8400 nid=0xfe4 waiting on condition [0x00000000
]
java.lang.Thread.State: RUNNABLE
"AWT-EventQueue-0" prio=6 tid=0x02b6e000 nid=0xcbc runnable [0x033fe000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- locked <0x22f33f30> (a java.io.BufferedInputStream)
at java.io.DataInputStream.readByte(Unknown Source)
at org.hsqldb.result.Result.newResult(Unknown Source)
at org.hsqldb.ClientConnection.read(Unknown Source)
at org.hsqldb.ClientConnection.execute(Unknown Source)
- locked <0x22f32700> (a org.hsqldb.ClientConnection)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeQuery(Unknown Source)
- locked <0x22be23b0> (a org.hsqldb.jdbc.JDBCStatement)
at posO2.Printer.flash(Printer.java:1058)
at posO2.Printer.bigFlash(Printer.java:1111)
at posO2.Panels.Accueil$5.actionPerformed(Accueil.java:314)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
"AWT-Shutdown" prio=6 tid=0x02b81800 nid=0xefc in Object.wait() [0x033af000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x27c707c0> (a java.lang.Object)
at java.lang.Object.wait(Object.java:503)
at sun.awt.AWTAutoShutdown.run(Unknown Source)
- locked <0x27c707c0> (a java.lang.Object)
at java.lang.Thread.run(Unknown Source)
"AWT-Windows" daemon prio=6 tid=0x03002800 nid=0xe58 runnable [0x0328f000]
java.lang.Thread.State: RUNNABLE
at sun.awt.windows.WToolkit.eventLoop(Native Method)
at sun.awt.windows.WToolkit.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"Java2D Disposer" daemon prio=10 tid=0x03000400 nid=0x4d0 in Object.wait() [0x03
1ef000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x27c2bf18> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
- locked <0x27c2bf18> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at sun.java2d.Disposer.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
"Service Thread" daemon prio=6 tid=0x02b63000 nid=0xb94 runnable [0x00000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread0" daemon prio=10 tid=0x02b54c00 nid=0x3f0 waiting on conditio
n [0x00000000]
java.lang.Thread.State: RUNNABLE
"Attach Listener" daemon prio=10 tid=0x02b53400 nid=0x924 waiting on condition [
0x00000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" daemon prio=10 tid=0x02b52000 nid=0xb88 runnable [0x00000000
]
java.lang.Thread.State: RUNNABLE
"Finalizer" daemon prio=8 tid=0x02b43c00 nid=0xfc8 in Object.wait() [0x02dff000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x27c2c148> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
- locked <0x27c2c148> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
"Reference Handler" daemon prio=10 tid=0x02b3f000 nid=0x488 in Object.wait() [0x
02daf000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x27c2bdd8> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source)
- locked <0x27c2bdd8> (a java.lang.ref.Reference$Lock)
"VM Thread" prio=10 tid=0x02b3d400 nid=0xa6c runnable
"VM Periodic Task Thread" prio=10 tid=0x02b76800 nid=0xf30 waiting on condition
JNI global references: 426
有人可以告诉我在哪里可以看到我的GUI由于第一个线程“ Thread-12”而被冻结。
其次,只要我确定我只运行过一次该线程,“ Thread-6”和“ Thread-7”之间有什么区别。
AWT-EventQueue-0
是您的事件分配线程,确实阻止了它
通过
套接字通过套接字从
RXTX
串行端口
读取hsqldb
。您应该使用SwingWorker
@Kumar建议的。在这里和这里都可以找到示例。我发现在探查器中研究此类示例很有帮助。
Thread-6
并且Thread-7
似乎属于您的应用程序的实例Threads.ThreadHorloge
在posO2
。关于线程名称:
每个线程都有一个名称供识别。一个以上的线程可能具有相同的名称。如果在创建线程时未指定名称,则会为其生成一个新名称。
请注意,SwingWorker
与Executors
通常包括文字 池-N ,其中 ñ 是一个序列号。
附录: 我的EDT处于一种 RUNNABLE
状态,因此从我粘贴的代码中,您可以确定它已被阻止; 您在哪里发现通过RXTX读取是阻塞原因?
抱歉,是我的错;
已更正。EDT并不是BLOCKED
在Thread.STATE
等待监视器锁定。从某种意义上说,它在等待数据库响应的过程中被阻塞,至少要足够长的时间,以便在您发送-QUIT
信号时在调用堆栈的顶部被看到。EDT上不应安排串行或网络操作。
我在swing中有一个Gui应用程序,可以在串行热敏打印机上打印票据。当我按下启动此操作的按钮时,我的GUI被冻结。我想那是因为代码是在EDT上执行的。我确实使用了jstack,但我不理解下面的结果: 有人能给我解释一下,我可以看到我的GUI冻结,因为第一个线程"Thread-12"。 第二,“线程6”和“线程7”有什么区别,只要我确定我只运行了一次这个线程。
我是Swing的新手,所以这似乎是一个非常天真的问题。 我有一个JFrame,它显示一个初始语句和两个单选按钮。RadioButton1表示接受,RadioButton2表示拒绝。如果用户选择接受,程序将继续。因此,我为Accept创建了一个ActionListener,以便我的其余代码都在这个ActionListener中。然而,只要用户按下Accept,GUI就会冻结。按Reject键只是程序
我创建了一个摇摆图形用户界面和一个使用JavaFX的图形。我想通过点击摇摆图形用户界面上的按钮来打开图形。我的代码在下面。谢谢你的帮助。 这就是我必须从swing GUI打开FX GUI的内容。 外汇类
问题内容: http://i.stack.imgur.com/XvHm5.png 当我单击“打开”按钮时,它将开始在JTextField上发送垃圾邮件1。而是冻结整个GUI,包括关闭按钮。我正在使用while循环,当您再次单击jButton时,它将停止。因为jButton被冻结,所以我无法停止该程序。我已经读过线程和多线程将有所帮助,但是所有教程都太复杂了,以至于我无法理解。他们说将循环和GUI放
我有点不明白:我的Swing GUI包含一个“播放”和“暂停”按钮。我还有一个静态变量,定义“开”和“关”状态。(主程序生成GUI)。通过点击“play”,我将静态变量的状态更改为“on”,并在一个线程中启动一个耗时的过程,该线程也会修改GUI。只要静态变量在同一进程中“开启”循环。单击“暂停”会将静态变量更改为关闭。但通过点击“播放”,GUI会冻结,因此: GUI不更新 我的暂停按钮无法暂停进程
问题内容: 我有一个程序在其中加载文件,同时显示一个窗口以通知用户正在加载文件。我决定制作一个FileLoader类,它是一个实际上处理了文件加载的SwingWorker类,以及一个实现PropertyChangeListener的ProgressWindow,用于通知用户传递给它的SwingWorker的状态。 我的代码当前如下所示: 问题是,每当我调用loader.get()时,它都会冻结GU