We could use copy-on-write approach instead of copying on every pulse;
This means, in synchronized block, we'd set some flag:
synchronized(this) {
stagePulseListInUse = scenePulseListInUse = postScenePulseListInUse = true;
}
and unset them at the end of the pulse.
Then instead of full copies, do just reference copy:
final Map<TKPulseListener,AccessControlContext> stagePulseList = stagePulseListeners;
...
The add*Listener methods would look like:
synchronized(this) {
AccessControlContext acc = AccessController.getContext();
if (stagePulseListInUse) {
stagePulseListInUse = false;
stagePulseListeners = new WeakHashMap<>(stagePulseListeners);
}
stagePulseListeners.add(listener);
}
This means, in synchronized block, we'd set some flag:
synchronized(this) {
stagePulseListInUse = scenePulseListInUse = postScenePulseListInUse = true;
}
and unset them at the end of the pulse.
Then instead of full copies, do just reference copy:
final Map<TKPulseListener,AccessControlContext> stagePulseList = stagePulseListeners;
...
The add*Listener methods would look like:
synchronized(this) {
AccessControlContext acc = AccessController.getContext();
if (stagePulseListInUse) {
stagePulseListInUse = false;
stagePulseListeners = new WeakHashMap<>(stagePulseListeners);
}
stagePulseListeners.add(listener);
}