Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 125707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:12:06+00:00 2026-05-11T05:12:06+00:00

I have a servlet which processes a request for a long time. It suppose

  • 0

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?

I thougth checkError() on the response writer should do the trick, but it does not seam to work. Any ideas why?

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

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:12:07+00:00Added an answer on May 11, 2026 at 5:12 am

    The only real way of dealing with this is to have the browser constantly tell you that it’s still there, say every 5-10 seconds. If you go for a minute without hearing anything, you assume the client is gone and forget what you’re doing.

    There are several ways to implement this:

    • Meta refresh: I don’t like this because it’s disconcerting and obvious for the user;
    • An iframe that does that (less obvious); or
    • Some AJAX technique, which is probably the best option.

    There’s no real way you can detect if the client is still reading what you’re sending. It takes time for TCP connections to die and the path to the client is often indirect anyway (through proxies and so forth) so forget about detecting that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure what you mean by "wanting it through… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer 1.) I would recommend using the BackgroundWorker instead of separate… May 11, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer It seems to me that your original two unit tests… May 11, 2026 at 11:31 pm

Related Questions

I currently have a tomcat container -- servlet running on it listening for requests.
I have a GWT application that displays some charts rendered by JFreeChart. Every few
How do I call a url in order to process the results? I have
I have a servlet S which handles callbacks from a 3rd party site. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.