狠批JDK的Observer接口!!!(言重了....^_^)

类别:Java 点击:0 评论:0 推荐:

Oberver模式常被“标榜”为快速响应Client的变化,及时的将message分发给订阅者,kao ...

其实,默认的JDK API根本就满足不了所谓的快速响应,甚至不如传统的过程式的执行方式:(

来看看JDK的Oberver都做了些什么...

这是Observable类的一段通知Observer的代码

if (!changed)
                return;
            arrLocal = obs.toArray();
            clearChanged();
        }

        for (int i = arrLocal.length-1; i>=0; i--)
            ((Observer)arrLocal[i]).update(this, arg);
    }

 

这个Update方法通知注册的观察者,若前一个观察者将耗时很长时,第二的则需要等待.....汗....

仔细看了JDK的说明

The order in which notifications will be delivered is unspecified. The default implementation provided in the Observerable class will notify Observers in the order in which they registered interest, but subclasses may change this order, use no guaranteed order, deliver notifications on separate threads, or may guarantee that their subclass follows this order, as they choose.

说的很明白了,我们只有自己去开多线程去解决这个问题........

 

本文地址:http://com.8s8s.com/it/it13833.htm