1
下面的链接介绍如何使用服务接口启动(以处理吉斯模块的初始化和销毁)和stop()方法:Guice中的模块初始化和销毁处理程序?
http://code.google.com/p/google-guice/wiki/ModulesShouldBeFastAndSideEffectFree
文档解释说,服务的创建看起来像这在客户端代码:
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(
new DatabaseModule(),
new WebserverModule(),
...
);
Service databaseConnectionPool = injector.getInstance(
Key.get(Service.class, DatabaseService.class));
databaseConnectionPool.start();
addShutdownHook(databaseConnectionPool);
Service webserver = injector.getInstance(
Key.get(Service.class, WebserverService.class));
webserver.start();
addShutdownHook(webserver);
}
但没有列出具体服务类的任何示例实现。任何人都可以提供给我一个吗?至少包含start()和stop()所包含内容的示例实现。
详细说明可以在这里找到:http://hellotojavaworld.blogspot.co.il/2010/11/runtimeaddshutdownhook.html – forhas