I'm using AWT, and specifically a TextField component with an added java.awt.event.FocusListener to receive events when a User focuses in and out of the TextField.
This is just an introduction, not my real issue, and the important features of my class is down below if it helps put things into perspective (minus AWT's window close events listener, so you can't close the window unless you use the Control+C keyboard,
Java's cut-off shortcut on Windows/Mac OS X (at least), at the command line/terminal).
Now, my question, when Java calls a method when does the method return instantly, when does it block until completed? I have heard that the Java GUIs (Swing, AWT) has an events dispatch
thread which will trigger my listerners, and I have also heard that these event calls can block waiting for methods to return. So, I want to avoid hogging the GUI event thread.
I'm trying to decide if I should use a Thread/Runnable or a method call, or even just run logic on the event dispatch thread.
I want to find out when and how I can start methods then return instantly?
Is it methods with void return type? Can Java just run them and instantly return because it doesn't need to wait for a return to be computed?
Okay, yes, I do know about Threads/ Runnable, but I really want to know how Java chooses to wait for a method or when to move on.
Is it safe to start a thread from an Event Listener ? I mean if event calls really block until finished, I think, it might become stuck waiting for any Threads, if defined in the event call method, to finish and become garbage collected before it can continue other event calls.
Wouldn't that blockage also happen if an Event listener calls a method to do the work?