After reading the information about the Java
class java.awt.EventQueue
on Oracle it is still not clear where this class is used for and what you can do with it. Can someone explain this for me please.

- 259
- 1
- 6
- 18
-
Are you familiar with terms "Event" and "Queue" in isolation? – bhspencer Sep 22 '15 at 12:04
-
Event yes, Queue not really. – John Doe Sep 22 '15 at 12:05
-
1Well have you ever waited in line? Now you know what a queue is. – Kayaman Sep 22 '15 at 12:06
-
1It's a FIFO (first in, first out) queue for AWT events. – meskobalazs Sep 22 '15 at 12:08
1 Answers
A queue is exactly what its name says - a line, where the first customer to arrive will be served first. So EventQueue is a line of events wainting to be dispatched.
What happens is that it is not always possible to handle events as they happen. Sometimes one event is being handled when another happens (for instance, a clock ticked at the same time a key was pressed - one will wait for the other to be handled), so it must wait. In order to ensure a certain fairness, events are dealt in order of arrival (hence the queue).
Another cause for the need of a queue is the habit many programmers have to perform long computations inside a event handler (and calling a method from inside the event handler qualifies as "inside it"). Hence, for a long time your application won't be able to deal with events and all those that happen while you are processing will be stored in the queue, for later dispatch.
I hope it helps.

- 2,053
- 1
- 12
- 13