Brew singleton

来源:互联网 发布:中海达dat数据导出 编辑:程序博客网 时间:2024/05/19 18:47

When a class is instantiated as a singleton in Brew® Mobile Platform (Brew MP), there can be only one instance of the class within a certain scope. The scope is determined by the environment (or Env) of the caller, or the entire Brew MP system, depending on the type of singleton class instantiated.

 

既所谓的单件并不是指在所有范围内都只有一个实例,而是在一定范围内.既文中的certain scope,这个范围是由调用者所处的Env(上下文)所决定的.也就是说singleton是在同一个Env中只有一个实例.

Singleton in-process calss:

在Brew Shell中的applet object,每个applet object都运行在各自的Env中,故即使in-process class是singleton类型的,在Brew shell中的applet在实例化这些类时也会在各自的Env中创建实例.也就是实际上没有进行实例共用.

而对于service object,他们或者运行在kernel process(这是一个Env),或者运行在service process中(另一个Env),因此在这些范围内,一个in-process singleton class只会有一个实例.所有调用他们的service object都共用一个实例.      

 

 

Singleton service:

对于service单件,这个范围这是全系统,所有要访问single service的object都共用一个service实例.由于service object运行在service process中,因此kernel process和BREW process中的对象要访问service object时要使用IPC方式.