我在课堂下面,当我第一次调用函数Main.getInfo(query)
时,我读了一些Object文件。我不希望每次调用服务时都执行所有读取对象。如何在某处保存这些信息。目前它每次读取这些对象时都太慢了。
public class MyServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String query = request.getParameter("query");
request.setAttribute("query", query);
System.gc();
List<MyObj> result=null;
try {
result = Main.getInfo(query);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
request.getRequestDispatcher("/results.jsp").forward(request, response);
}