6

I am new to Java Swing and my question is related to Event Queues and Dispatch threads.

I read that it is possible to have multiple event queues , each per AppContext instance. Similarly does it mean each AppContext Event queue has its own event dispatch thread.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Sirish
  • 9,183
  • 22
  • 72
  • 107

2 Answers2

3

It is only possible to have one event dispatch thread as far as I'm aware.

Apparently AppContext is not meant to be used by developers, although I'm not really familiar with it.

Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
  • 1
    I came to know that each AppContext usually assigned for a separate thread group has its own queue, which indirectly says it has its own EDT – Sirish Sep 18 '11 at 08:04
  • I guess having two AppContexts running on the same JVM would give you two EDTs, although they are for most purposes completely separate programs. – Garrett Hall Sep 18 '11 at 20:00
1

1) basically you only needed to know if your code will be done on EDT (all changes must be done on EDT),

2) if you have any doubts, it is possible to test

if (EventQueue.isDispatchThread()) {

or (that's same and returns true if is on EDT)

if (SwingUtilities.isEventDispatchThread()) {

more here or here

3) all output from Background tasks must be wrapped into invokeLater(), basic stuff about Concurency in Swing

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319