什么是SwingUtilities.invokeLater办? [英] What does SwingUtilities.invokeLater do?

查看:289
本文介绍了什么是SwingUtilities.invokeLater办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么 SwingUtilities.invokeLater 吗?难道仅仅是延缓codeS块的内部的执行运行的方法?是什么调用的invokeLater 函数中的动作或只是在我们想要的线程结束调用它要执行的区别?谁能帮我什么确实的的invokeLater 函数呢?

What does SwingUtilities.invokeLater do? Is it just delaying the execution of a block of codes inside its run method? What is the difference between calling an action within the invokeLater function or simply calling it at the end of the thread we want to be executed? Can anyone help me with what really does the invokeLater function do?

推荐答案

至于其他的答案已经说过,它执行你的的Runnable AWT事件派发线程。但是,你为什么要这么做?由于摆动数据结构不是线程安全的,所以为程序员提供preventing给他们的并发访问的易于实现的方式,摇摆设计师定下的规则,所有code访问它们必须运行在相同的线程。对于事件处理和显示维修code自动发生的,但如果你已经启动了一个长期运行的动作 - 在一个新的线程,当然 - 你怎么能信号,其进度或完成?您必须修改一个Swing控件,你必须从事件派发线程做。因此,的invokeLater

As other answers have said, it executes your Runnable on the AWT event-dispatching thread. But why would you want to do that? Because the Swing data structures aren't thread-safe, so to provide programmers with an easily-achievable way of preventing concurrent access to them, the Swing designers laid down the rule that all code that accesses them must run on the same thread. That happens automatically for event-handling and display maintenance code, but if you've initiated a long-running action - on a new thread, of course - how can you signal its progress or completion? You have to modify a Swing control, and you have to do it from the event-dispatching thread. Hence invokeLater.

这篇关于什么是SwingUtilities.invokeLater办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆