1 17 package org.apache.servicemix.beanflow.support; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 28 public class SynchronousNotifier implements Notifier { 29 private List <Runnable > listeners = new ArrayList <Runnable >(); 30 31 public void addRunnable(Runnable listener) { 32 synchronized (listeners) { 33 listeners.add(listener); 34 } 35 } 36 37 public void removeRunnable(Runnable listener) { 38 synchronized (listeners) { 39 listeners.remove(listener); 40 } 41 } 42 43 public void run() { 44 Runnable [] array = null; 45 synchronized (listeners) { 46 array = new Runnable [listeners.size()]; 47 listeners.toArray(array); 48 } 49 for (Runnable listener : array) { 50 listener.run(); 51 } 52 } 53 54 } 55 | Popular Tags |