Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

awt - About the EDT (Java)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...