What does the Java class Eventqueue exactly do?

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.

Answer

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.

Leave a Reply

Your email address will not be published. Required fields are marked *