Results 1 to 6 of 6

Thread: What is the Event Dispatch Thread in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    What is the Event Dispatch Thread in Java?

    Hi friends,
    I am new to the Java programming language. So i don't know much about the Java. While processing an events the event dispatch thread is used. I know other than this about the event dispatch thread. I want some information about it since it is very important. So please explain me in details what is the Event Dispatch Thread in Java? Any other information related to the topic would also be appreciated.
    Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991

  2. #2
    Join Date
    Jul 2006
    Posts
    286

    Re: What is the Event Dispatch Thread in Java?

    Swing event handling code runs on a special thread known as the event dispatch thread. The swing methods which gets invoked by many codes also runs on this thread. EventDispatchThread is a package-private AWT class. The event dispatching thread (EDT) is a background thread used in Java to process events from the AWT. In single-thread rule swing components can be accessed by only one thread at a time. Mostly this thread is the event-dispatching thread. EventDispatchThread starts a "permanent" event pump with a call to pumpEvents in its run() method.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the Event Dispatch Thread in Java?

    You can also execute the coding of the other application threads in the event dispatching thread. For doing this you will have to define the code in a Runnable object and pass it to the SwingUtilities helper class or to the EventQueue. There are two methods of this class which are described as follows :
    • synchronous code execution
    • asynchronous code execution

    The first method can be written as synchronous code execution (SwingUtilities.invokeAndWait(Runnable) or EventQueue.invokeAndWait(Runnable)) while the second can be written as asynchronous code execution (SwingUtilities.invokeLater(Runnable) or EventQueue.invokeLater(Runnable)).

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is the Event Dispatch Thread in Java?

    The worker design pattern can also be used for executing code in the event dispatch thread. The SwingWorker class which is developed by the Sun Microsystems, is an implementation of the worker design pattern. The open source project Foxtrot provides another synchronous execution solution similar to SwingWorker. Swing object methods are not "thread safe": invoking them from multiple threads risks thread interference or memory consistency errors. All other Swing component methods must be invoked from the event dispatch thread.

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is the Event Dispatch Thread in Java?

    If you want to check that whether your code is running on the event dispatch thread, then you will have to invoke javax.swing.SwingUtilities.isEventDispatchThread. The isEventDispatchThread returns true if the current thread is an AWT event dispatching thread. It's useful to think of the code running on the event dispatch thread as a series of short tasks. Most tasks are invocations of event-handling methods, such as ActionListener.actionPerformed. The event dispatching thread is the only valid thread to update the visual state of visible user interface components.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: What is the Event Dispatch Thread in Java?

    I think that you should also have to know about the methods provided by the SwingUtilities for running code in that thread. The following are the two methods which are provided by the SwingUtilities to help you run code in the event-dispatching thread :
    invokeLater() - Without waiting for the code to execute, this method is returned immediately. The main function of this method is to requests that some code be executed in the event-dispatching thread.
    invokeAndWait() - Acts like invokeLater(), except that this method waits for the code to execute.

Similar Threads

  1. Synchronize a producer thread and a consumer thread in C#
    By Ayuka in forum Software Development
    Replies: 6
    Last Post: 10-11-2010, 04:04 AM
  2. Control thread speed in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 14-02-2010, 05:29 AM
  3. Thread scheduling In Java
    By samualres in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 06:50 PM
  4. Thread Priorities in java
    By Aakarshan.d in forum Software Development
    Replies: 3
    Last Post: 08-12-2009, 02:02 PM
  5. Replies: 2
    Last Post: 19-07-2007, 10:31 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,912,926.49799 seconds with 17 queries