java - Concurrency - postpone method execution -
this question has answer here:
how modify class:
public class event<t extends eventargs> { private final list<listener<t>> listeners; public event() { listeners = new arraylist<>(); } public void invoke(t args) { (listener<t> l : listeners) l.onevent(args); } public void addeventlistener(listener<t> l) { listeners.add(l); } public void removeeventlistener(listener<t> l) { listeners.remove(l); } }
so addeventlistener()
, removeeventlistener()
postponed execute after invoke()
ends (so won't concurrentmodificationexception
)?
depending on how long expect invoke()
run have 2 choices. if execution less short interval (i.e. 10ms) lock on class. otherwise need queue operations , have invoke method run them in sequence after it's done.
Comments
Post a Comment