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