Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
狠批JDK的Observer接口!!!(言重了....^_^)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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.

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

 




相关文章

相关软件