4
當我們通過JNDI對象的查找,我們做這樣的事情:當關閉JNDI上下文
public SomeResult doSomething() {
Context ctx;
try {
ctx = new InitialContext(properties);
SomeClass someObject = (SomeClass) ctx.lookup("jndiName");
SomeResult someResult = someObject.getResult();
return someResult
} finally {
ctx.close();
}
}
一位同事這樣做是有所不同是這樣的:
public SomeClass getSomeClass() {
Context ctx;
SomeClass someObject = null;
try {
ctx = new InitialContext(properties);
SomeClass someObject = (SomeClass) ctx.lookup("jndiName");
return someObject
} finally {
ctx.close();
}
}
那讓我想知道,哪一個使用?關閉上下文後返回的對象是否有效?這是通過純粹的巧合還是僅僅是爲了查找和對象(作爲ejb的代理)是自持的?
我試圖找到在JNDI-SPEC的東西......但一無所獲......但我可能只是盲目;-)
什麼是通過JNDI,並使用它來查找一個EJB的最佳實踐,並且出於何種原因。