如果我更早在Context和InitialContext中查看了Java SE6文档,我会看到每个方法都有一个close()
方法。Context和InitialContext - 我应该在这些对象上调用close()方法吗?
所以现在我想知道,我是否需要调用Context/InitialContext对象上的close()
方法?
这是我典型的servlet代码片段,以及如何使用Context/InitialContext对象。
public class MyTypicalServlet extends HttpServlet {
//thread safe
DataSource ds;
String FilePath;
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
final Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myDB");
FilePath = getServletContext().getInitParameter("FilePath");
} catch (NamingException e) {
throw new ServletException("Unable to find datasource: " + e.getMessage(), e);
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
//...a bunch of code
}
}//class
我确实调用'close()',但实际上没有impl。做任何事情,因为你可以有subContexts等等。 – bestsss 2011-02-25 18:19:26