Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Event handling and code execution - EventObject

What happens when a custom EventListener handles a custom EventObject?

Once the Handler is done:

  1. Does the execution go back to the standard thread code? or,
  2. Is the thread is closed?
like image 534
raf Avatar asked Jan 30 '26 16:01

raf


1 Answers

EventListener is only Interface (actually very low level) and it only defines what should be implemented. How it is implemented is defined in the class which implements this interface. So, question should be how some particular class handles it. It could be started in separate thread or new thread could be created or current one could be used. Different classes handle it differently. I believe that majority of them just call listener's method in current own thread. That's the reason why it is not advised to do anything long (actually anything at all except few commands to notify about event) inside listener itself. That's where flexibility comes - you decide what and when to do. Start new thread and finish it when job done or use existing thread or do your job quickly and hope that current thread doesn't stuck and, for example, GUI window is not frozen.

like image 178
Alex Avatar answered Feb 01 '26 08:02

Alex