其他分享
首页 > 其他分享> > SwingUtilities.invokeLater 解决DR project的bug:多线程下swing组件不稳定

SwingUtilities.invokeLater 解决DR project的bug:多线程下swing组件不稳定

作者:互联网

SwingUtilities.invokeLater

SwingUtilities.invokeLater(new Runnable() {

           public void run() {

           textControl.append(String.valueOf((char)b));

           }

});

---------

This makes the following line of code:

       textControl.append(String.valueOf((char)b));

to be executed not on the current thread, but on the Event Dispatch Thread (EDT). If you tried to execute it on your current thread, it would result in undefined behavior because Swing is not thread-safe and all GUI operations must happen on the mentioned EDT.

 

That simply adds a task to the tasks queue of the Java thread which is in charge of the rendering & events for your whole application.

Swing works on Single Threaded Model. All the updates to the UI related things should be done through Event Dispatch Thread.

 

标签:invokeLater,thread,SwingUtilities,valueOf,char,textControl,多线程
来源: https://www.cnblogs.com/rySZ/p/10654196.html