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

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.

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值