关于EDT(JAVA) [英] About the EDT (Java)

查看:131
本文介绍了关于EDT(JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读了有关的东西时,应在EDT运行,当它不应该号码在互联网上的文章。但我仍然不知道我知道,所以我想请教一下这几个问题:


  1. 什么code片会在默认情况下的内运行的EDT?


  2. 打算什么件code的需要为默认值运行的之外
    EDT?


  3. 当我应该使用的invokeLater()这样的东西,在默认情况下会
    在美国东部时间之外运行,将里面运行?


  4. 当我应该prevent从美国东部时间内运行(默认),通过创建一个新的线程,并把该code里面一片code的?


感谢


解决方案

  1. 所有由事件监听器执行code。

  2. 在main方法的code,一个线程中执行code,你明确地开始,或已经由定时器或SwingWorker类的使用开始。

  3. 当创建在main方法的Swing GUI的。或者当你要与从后台线程里面Swing组件(或模型)进行交互。

  4. 当这片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:

  1. What pieces of code are going to run by default inside the EDT?

  2. What pieces of code are going to be run be default outside the EDT?

  3. When should I use InvokeLater() so something that by default would run outside the EDT, will run inside it?

  4. 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

解决方案

  1. All the code executed by an event listener.
  2. 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.
  3. 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.
  4. 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屋!

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