How does an ActionListener work?

后端 未结 3 855
误落风尘
误落风尘 2021-01-04 14:02

I have an idea of how to use action listeners and implementing them but I was wondering if anyone could tell me how do they listen to the events? Is there some kind of poll

3条回答
  •  灰色年华
    2021-01-04 14:09

    Action listeners register for Events using the Observer pattern and they are notified, by the main event loop, of any events they are registered for. So no, it's not a polling (pull) mechanism, but the opposite - a (push) callback. This is an example of 'don't call us, we'll call you' programming. Because everything in your code runs off a single thread (the event loop) you don't have to worry about synchronizing between different events - so your code is threadsafe.

提交回复
热议问题