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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -