Questions tagged [event-dispatch-thread]

The event dispatch thread, or EDT, is a special background thread which handles events from the Java GUI event queue. Swing and Android have different implementations but they are similar in concept.

This thread must never be stalled with some computationally intensive or otherwise slow task (like networking), as the GUI stops responding to user input until the call returns.

As Java GUI environments are not thread-safe, it is the only thread that can safely touch GUI components (instantiating and updating GUI components, including setting values for text fields and the like). If any other thread must do this, this should be done through a wrapper method that runs on the EDT. In Swing, the wrapper method is SwingUtilities.invokeAndWait or SwingUtilities.invokeLater. In Android, Activity.runOnUiThread serves the same purpose.

775 questions
5
votes
3 answers

Is there a way to set up two or more the event dispatch thread (EDT)?

Is Java capable of creating more than one EDT at a time? I'm experimenting with setting up EDT and how it works in updating the content of a "heavy duty" panel with potentially a dozen of panels embedded inside and with hundreds of components…
mk7
  • 150
  • 1
  • 9
5
votes
1 answer

Error handling in SwingWorker

My question is a theory-based question, but it does meet a specific need I have. What do you do when your SwingWorker throws an Exception that you a) can anticipate and b) need to recover from and continue, but you want to notify the user that this…
ryvantage
  • 13,064
  • 15
  • 63
  • 112
5
votes
1 answer

How To Check Whether EDT (Event Dispatch Thread) Has finished with Dispatching Events In Java

In my tool, I record events generated from user application. Now user can use my tool to replay his scenario. While replaying user's recorded scenario, I post recorded events to "EventQueue" one by one using: eventQueueObj.postEvent(eventObj); In…
Yogesh Ralebhat
  • 1,376
  • 1
  • 13
  • 29
5
votes
1 answer

converting to ScheduledThreadPoolExecutor

I am still a beginner at Java so I have not learned much about threads and concurrency. However, I would like to be able to use the ScheduledThreadPoolExecutor as a timer because of the problems I am having with java.util.Timer and TimerTask. I am…
5
votes
3 answers

Create swing components at runtime

i created the application and it behaves pretty much as expected. the gui keeps responsive as long as the database query is running. when creating the custom panels with SwingUtilities.invokeLater() the gui freezes for a very short amount of…
5
votes
4 answers

using sleep() for a single thread

I am fairly new to java, and am starting to get into using different threads in order to use wait() or sleep() on one part of my code and have the others still run. For this project, I am using JFrame with the javax.swing.* and java.awt.* imports.…
Harper
  • 140
  • 2
  • 4
  • 10
5
votes
1 answer

Should i use SwingUtilities.invokeLater() inside of SwingWorker.doInBackground()?

The common way to interact with EDT from swing worker is useing get() method. But i have a long task and code like this: public Void doInBackground() { for(Object o : objects) { doSomething(); …
AvrDragon
  • 7,139
  • 4
  • 27
  • 42
5
votes
3 answers

accessing variables and swing components through different threads

This question is related somewhat to the one i asked HERE. Now, i have a class "Controller" which consists of the main method and all the swing components. there is a class named "VTOL" which consists of a variable named "altitude"(i have declared…
md1hunox
  • 3,815
  • 10
  • 45
  • 67
4
votes
3 answers

Java API "Run on EDT if not on EDT"

Just a musing about some repetitive code I have: Runnable run = new Runnable() { @Override public void run() { // Some EDT code } }; if (!EventQueue.isDispatchThread()) { SwingUtilities.invokeAndWait(run); } else { run.run(); } It's…
Whired
  • 259
  • 1
  • 11
4
votes
2 answers

Flow of execution when using Swing

I'm just getting to grips with GUI programming in java. Here is a trivial program (from O'Reilly's "Head First Java") which on the face of it looks easy to understand, but there's an aspect of it which I don't follow. import javax.swing.*; public…
Kevin Buzzard
  • 537
  • 4
  • 11
4
votes
1 answer

Java: second window is blank

I have a weird issue... I'm a relatively new "enthusiast" Java programmer (I used to make my living hacking Perl, in a previous career), working on my first semi-real application. "Main-Class" is the MyApp class, which creates a UserInputDialog…
4
votes
1 answer

Deadlock when using setText on JTextArea in Swing

I have the following Java Program which one starts in about 50% of all launch attempts. The rest of the time it seams to deadlock in the background without displaying any GUI. I traced the problem to the setText method of the JTextArea Object. Using…
Christian
  • 241
  • 6
  • 14
4
votes
3 answers

java SwingWorker launching runnables from doInBackground() and howto notify event dispatch thread

just learnd the SwingWorker and have a question ( i have search for a answer to this but non specifically address this setup) Im creating a small server that will have like max simultaneous 2-3 connections only. Im using a Jframe that have the inner…
Erik
  • 5,039
  • 10
  • 63
  • 119
4
votes
2 answers

Java Swing EDT & Concurrency

I was just wondering if it is still necessary to ensure synchronicity in an invokeLater() Runnable. I am encountering deadlock and need to overcome it while maintaining concurrency. Would this be an example of good code?: private String…
Whired
  • 259
  • 1
  • 11
4
votes
1 answer

Creating an Event Dispatch Thread safe semaphore

I've been trying to make a binary semaphore that will be able to safely block execution of a method running on the event dispatch thread (EDT) without actually blocking the thread from handling more events. This may initially seem impossible, but…
NateW
  • 908
  • 1
  • 8
  • 28