SYNCHRONIZED in AddXXXListener

zhaozj2021-02-16  93

It turned out that there was a function of helping the event with JBuilder, but the addXxxListener, RemovexxxListener, the method of the resocExxEvent, and a Synchronized keyword, not understood, until the recent event involves multi-threaded events. It was only useful, but the event handling method generated in JBuilder was slightly unpleasant, that is, if there is AddXxxListener or RemovexxListener or RemovexxxListener in the Listener, it will be compared to the range of SYNCHRONIZEDs, if the event listener There will be a long running time, so I made a public collection synchronized getxxxlistener () {return new arraylist (xxxListeners);} Remove the SYNCHRONIZED in the Firexxx method sign again, then use the xxxlistener to change GetxxListeners (), even You can notify each listener to make threads (see if there is a synchronous asynchronous effect). Such event processing should be comparable to BUG that should be accepted and not above. There is also a scheme, which is to change XXXListeners to use Vector, so add, remove, get can remove synchronized, because the vector itself is a synchronized version of Collection.

转载请注明原文地址:https://www.9cbs.com/read-11876.html

New Post(0)