user489041
user489041

Reputation: 28304

Object Creation on EDT

I think the easiest way to ask my question is to build up to it. I am slightly confused on some of the workings of the EDT.

Is any object created from a Swing component created on the EDT?

To expand on this question, If I create a JFrame, and in its constructor, it creates Objects X,Y, and Z, are X,Y,Z also created on the EDT?

To further expand this question, if during class creation of X, it becomes blocked waiting on a network resource, will this then block the EDT?

Upvotes: 1

Views: 83

Answers (1)

camickr
camickr

Reputation: 324118

Is any object created from a Swing component created on the EDT?

Only if your code is running on the EDT. Code executed in an Event Listener is automatically executed on the EDT.

When you start your GUI via the main() method it is NOT running on the EDT unless you specifically place the code on the EDT. This is usually done by using SwingUtilities.invokeLater().

Read the Swing tutorial on Concurrency for more information. Also read the Table of contents, specifically the section on How to Make Frames for a simple example of starting your code on the EDT.

if during class creation of X, it becomes blocked waiting on a network resource, will this then block the EDT?

Again, only if the block of code was executed on the EDT.

Upvotes: 3

Related Questions