首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Guice Stages (运作阶段)

2012-11-03 
Guice Stages (运行阶段)Guice还有一个特效,可以指定Guice运行模式来控制Guice的加载速度。在com.google.in

Guice Stages (运行阶段)

Guice还有一个特效,可以指定Guice运行模式来控制Guice的加载速度。在com.google.inject.Stage枚举中提供了TOOL,DEVELOPMENT,PRODUCTION三种模式。

TOOL描述的是带有IDE等插件的运行模式;DEVELOPMENT是指在开发阶段只加载自己需要的功能(对于非立即初始化单例对象采用延后加载),这样来降低加载不需要功能的时间;而PRODUCTION模式是指完全加载所有功能(对于单例对象采用立即加载方式),这样可以更早的发现问题,免得等需要某些功能的时候才发现问题(要知道我们某些功能可能需要特定的条件才能触发)。

其实只有比较多的单例对象,并且单例对象构造比较耗时的情况下才能有用。大部分情况下这点性能可能都忽略不计了。

默认情况下Guice采用DEVELOPMENT模式。

?

see codes

? /**
?? * Creates an injector for the given set of modules, in a given development
?? * stage.
?? *
?? * @throws CreationException if one or more errors occur during injector
?? *???? construction
?? */
? public static Injector createInjector(Stage stage,
????? Iterable<? extends Module> modules) {
??? return new InternalInjectorCreator()
??????? .stage(stage)
??????? .addModules(modules)
??????? .build();
? }

热点排行