I'm writing a Spring web application and I'm mapping the "/do" URL path to the following Controller's method

@Controller
public class MyController
{
    @RequestMapping(value="/do",  method=RequestMethod.GET)
    public String do()
    {
        File f = new File("otherMethodEnded.tmp");
        while (!f.exists())
        {
            try {

                Thread.sleep(5000);

            } catch (InterruptedException e) {

            }
        }

        // ok, let's continue
    }
}

The otherMethodEnded.tmp file is written by one another Controller's method, so when the client calls the second URL I expect the first method to exit the while loop.

Everything works, except when the client calls the "/do" URL and then closes the connection before the response was received. The problem is that the server remains in the while (!f.exists()) loop even though the client is down and cannot call the second URL to unlock the while loop.

I would try to retrieve the connection status of the "/do" URL and exit the loop when the connection is closed by the client, but I cannot find any way to do so.

I tried with the HttpServletRequest.getSession(false) method but the returned HttpSession object is always not null, so the HttpServletRequest object is not updated in case of connection close of the client.

How can I check whether the client is still waiting for the risponse or not?

Related posts

Recent Viewed