public interface CallbackService{ void addListener(String key,CallbackListener listener); } public interface CallbackListener{ void changed(String msg); } public class CallbackServiceImpl implements CallbackService{ private final Maplisteners = new ConcurrentHashMap (); public void addListener(String key,CallbackListener listener){ listeners.put(key,listener); } public CallbackServiceImpl(){ Thread t = new Thread( new Runnable(){ public void run(){ while(true){ try{ for(Map.Entry entry: listeners.entrySer()){ try{ entry.getValue().changed(getChanged(entry.getKey())); }catch(Throwable t){listeners.remove()} } }catch(Throwable e){listeners.remove(entry.getKey())} } } } ); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)