关于EDT(JAVA) [英] About the EDT (Java)
问题描述
我已经读了有关的东西时,应在EDT运行,当它不应该号码在互联网上的文章。但我仍然不知道我知道,所以我想请教一下这几个问题:
-
什么code片会在默认情况下的内运行的EDT?
-
打算什么件code的需要为默认值运行的之外的
EDT? -
当我应该使用的invokeLater()这样的东西,在默认情况下会
在美国东部时间之外运行,将里面运行? -
当我应该prevent从美国东部时间内运行(默认),通过创建一个新的线程,并把该code里面一片code的?
感谢
- 所有由事件监听器执行code。
- 在main方法的code,一个线程中执行code,你明确地开始,或已经由定时器或SwingWorker类的使用开始。
- 当创建在main方法的Swing GUI的。或者当你要与从后台线程里面Swing组件(或模型)进行交互。
- 当这片code的阻塞(如长IO)或超过几毫秒的执行正在采取更多。所有从美国东部时间prevent内执行code这个线程从做它的主要工作:重绘GUI和反应事件。
I have read a number of articles on the internet about when something should run in the EDT, and when it shouldn't. But I'm still not sure I understand, so I'd like to ask a few question about this:
What pieces of code are going to run by default inside the EDT?
What pieces of code are going to be run be default outside the EDT?
When should I use InvokeLater() so something that by default would run outside the EDT, will run inside it?
When should I prevent a piece of code from running (by default) inside the EDT, by creating a new thread and putting that code inside it?
Thanks
- All the code executed by an event listener.
- The code in your main method, the code executed inside a thread that you explicitely started, or that has been started by the usage of a Timer or SwingWorker.
- When creating a Swing GUI in your main method. Or when you want to interact with a Swing component (or its model) from inside a background thread.
- When this piece of code is blocking (like long IO) or is taking more than a few milliseconds to execute. All the code executed from inside the EDT prevent this thread from doing its main job: repainting the GUI and reacting to events.
这篇关于关于EDT(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!