1 Reply Latest reply on Feb 21, 2008 12:05 PM by peterj

    How can I control infinite requests?

    bunkenburg

      What happens if the programmer writes an infinite request?

      What if we have a servlet that may take a very long or infinite time to complete? Does that mean that every time some one sends a request to that servlet, one of the threads goes away to execute the servlet and never comes back? Is there any way that JBoss can monitor and kill such a thread?

      Example servlet:


       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
       String s = request.getParameter("N");
       int N = Integer.parseInt(s);
       PrintWriter writer = response.getWriter();
       for (int i=0; i<N; i++){
       writer.println(i + "/" + N);
       System.out.println(i + "/" + N);
       Thread.sleep(1000);
       }
       } catch (NumberFormatException e){
       throw new ServletException(e);
       } catch (InterruptedException ie){
       throw new ServletException(ie);
       }
       }
      


        • 1. Re: How can I control infinite requests?
          peterj

          Yes, if the request goes into an infinite loop, that request will continue to hold onto the thread. I have seen several thread dump where that has been the case. If you get enough of such requests, eventually all threads will be in use. I know of no way within jbossas to kill such a thread. You could beat up on the developer though and tell him/her not to do that. If there is a long running request, using an alternate means to process the request might be preferable, for example, use jms to process the request asynchronously.