If client terminates the connection the server will close it after the
timeout (should be specified in server configuration). Another thing is that
IMHO it is not a good idea to manage threads manually inside of any
component - you should leave it for container, it is container's job to
control threading for you.

-- 
Regards,
Artashes Hovasapyan


On Fri, Feb 6, 2009 at 1:31 PM, Mikhail Gerdov <ger...@gmail.com> wrote:

>
> Hi,
>
> I have a servlet which processes a request for a long time. It suppose
> to keep doing stuff in the loop inside doPost and send data through
> response's out writer. Effectively that continuously appends data in
> the clients browser .
> But the problems accures when client just closes the browser. Inspite
> of the broken connection the response's writer stream in the servlet
> never gets closed, thus servlet is unaware of the brocen connection,
> and keep dumping data into the writer without any errors. How is that
> posssible? And how do I detect and cancel long request processing in
> case of browser disconnect?
>
>
> This is the servlet code which never stops:
>    protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
>            throws ServletException, IOException
>    {
>        HttpSession session = request.getSession();
>        System.out.println("Session " + session.getId() + " started");
>
>        response.setContentType("text/html;charset=UTF-8");
>
>        PrintWriter out = response.getWriter();
>        try
>        {
>            while (!out.checkError())
>            {
>                try
>                {
>                    Thread.sleep(1000);
>                } catch (InterruptedException ex)
>                {
>                    ex.printStackTrace();
>                }
>
>                Date date = new Date();
>
>                // TODO append output to the client browser here
>                out.println(".....");
>
>                System.out.println("Session " + session.getId() + "
> data sent at: " + date);
>
>                out.flush();
>            //break;  // _TEST
>            }
>        } finally
>        {
>            System.out.println("Session " + session.getId() + " finished");
>            out.close();
>        }
>    }
>
>
> Thanks,
> Mike
>
>
> --
> Best regards,
> Mikhail Gerdov                                     mailto:ger...@gmail.com
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Java 
EE (J2EE) Programming with Passion!" group.
To post to this group, send email to 
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to 
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to