title: HttpServlet: how to save objects in service function?
body: <p>I have below class, when I call the function <code>Main.getInfo(query)</code> for the first time I read some Object files. I don't want to do all the read Objects each time service is called. How can I save these information somewhere. Currently it is too slow as each time it reads those objects.</p>
  
  <pre><code>    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&lt;MyObj&gt; result=null;
      try {
          result = Main.getInfo(query);
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      }
      request.getRequestDispatcher("/results.jsp").forward(request, response);
  }
  </code></pre>