title: Static or nonstatic action in mvc?
body: <p>i want to ask you about mvc. How it works. So, this is simple example(I don't use any frameworks)   </p>
  
  <p>in Controller(Servlet):</p>
  
  <pre><code>protected void doGet(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
      processRequest(request, response);
  }
  
  protected void doPost(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
      processRequest(request, response);
  }
  
  private void processRequest(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
      String page = null;
      AbstractCommand action;
  
      action = ActionFactory.getAction(request);// get command from factory
      page = action.execute(request, response); 
      RequestDispatcher dispatcher = getServletContext()
              .getRequestDispatcher(page);
      dispatcher.forward(request, response);
  }
  </code></pre>
  
  <p>for action we create a common interface(Strategy pattern):</p>
  
  <pre><code>public interface AbstractAction {
  
      public String execute(HttpServletRequest request, HttpServletResponse response);
  }
  </code></pre>
  
  <p>Simple Action(Example):   </p>
  
  <pre><code>public class HelloAction implements AbstractAction {
  
      @Override
      public String execute(HttpServletRequest request,
              HttpServletResponse response) {
          //....(some actions to modify request)
          String page = "/main.jsp";
          return page;
      }   
  }
  </code></pre>
  
  <p>And now, our factory:   </p>
  
  <pre><code>public class ActionFactory {
  
      private enum Actions{
          HELLO;
      }
  
      public static AbstractAction getAction(HttpServletRequest request){
          String action = request.getParameter("action");//take parameter from jsp
          Actions actionEnum = Actions.valueOf(action.toUpperCase());
          switch (actionEnum) {
          case HELLO:
              return new HelloAction(); 
          }
      }
  }
  </code></pre>
  
  <p>We came to the place where I am in confused. Servlet is initialized only once, and only one for all requests. Just forwards requests to the actions where we modify request or response. But, we create NEW instance of the class for every request. Here can occur memory overflow!? Or not? </p>
  
  <p>Can we make these actions static(static method, one for all request)? If two requests come at the same time what will happen to them?<br>
  What do you think about this, please share your experience.</p>
  
  <p>P.S. sorry for bad english.</p>