Hot questions for Using Transmission Control Protocol in jakarta ee

Question:

I am trying to process some business logic after user hit a URL. There will be a heavy loop running in server side. The browser will be loading (we can see the spinning animation on top) while waiting server return the result.

We don't discuss is that correct or not to perform heavy loop in HTTP connection, my question is that, while the browser is waiting for the result, and, if user want to stop the processing, by closing the browser/tab or pressing ESCAPE or pressing the "X" cross button (at the browser bar), likely, the browser will stop to receive any data from server side. Now, my problem is, the server thread that is processing heavy loop will not stop somehow (even browser not to receive data anymore). How am I going to stop that?

I thought that, according TCP transmission, if one end of sockets is closed, another end will be notified and closed as well. I expect my server will have something like "socket close exception" thing thrown out by the Servlet. But it is not, so the loop in Servlet is still running until it finished. Any idea how can I stop it? It will lead to "Out of memory" issue if the user keep on hitting the URL and cancel the request.


Answer:

Try to do something like this:

  1. Create service for processing your heavy loop in new threads (manually created by you).
  2. When user hits URL in browser create thread with heavy loop in new thread (by processing service) and return to user some internal id of this thread (this id may be generated by you) which will allow you to identify this thread in service from point 1.
  3. Make some kind of pinger from client to server (for example on every 5 seconds client will ping processing service with thread id). Write last time of ping for this thread in thread-processing service.
  4. In thread-processing service from point 1, create next thread for checking each thread if ping was in last 5 seconds. If not - interrupt thread.

Question:

My understanding of long polling is, sending a request to server, and server taking some time to return data to us, or gradually send back the data.

I encounter a problem with my java servlet app (run in weblogic server), after client fire a request, the processing time of the backend servlet took about 1 minute, when the servlet trying to send back the response, I encounter "broken pipe" problem.

This problem is reported by my client, I can't reproduce it in my environment, in fact, I written a small servlet to test when I will eventually encounter the read-timeout issue. Un-surprisingly, my browser can be waiting server to return response for more than 5 minutes.

What could be the reasons that my client encouter such broken pipe issue?

How possibly can I solve it?

According to http://support.microsoft.com/en-us/kb/813827,

Internet Explorer reuses the same TCP/IP socket that was used to receive the initial request until the socket is idle for one minute. After the connection is idle for one minute, Internet Explorer resets the connection. A new TCP/IP socket is used to receive additional requests.

Is that possible the keep-alive timeout (1 minutes) actually overwrite the 'read-timeout' (my understand 'read-timeout' has very damn long timing), so it cause the TCP connection close?

So now, this also come back with a question, when it says "idle for one minute", what is the definition of "idle"? now TCP open a socket and send out the request, while waiting server to process large data and return, does it mean it is "idle" now?


Answer:

Is that possible the keep-alive timeout (1 minutes) actually overwrite the 'read-timeout' (my understand 'read-timeout' has very damn long timing), so it cause the TCP connection close?

No, neither the HTTP keep-alive nor the TCP keep-alive (it is unclear which one you actually mean and they have different meanings) have anything to do with timeouts because the socket is idle.

what is the definition of "idle"?

Idle means no data get transferred.

Question:

I setup geronimo on ec2 cent os environment.It started successfully.It is running on port 8080.I am able to telnet on the server.But when i telnet outside the server, unable to connect to the server.Do i need to change any configuration ?

when i ran netstat -an.I can see the following line.

tcp        0      0 :::8080                     :::*                        LISTEN 

Thanks and Regards.


Answer:

The connection is block by iptables.due to this i am unable to telnet from outside the machine. This is happening only on ec2 centos machine.I checked on ubuntu and connections are not blocked.Once solution is to stop the iptables service.

service iptables stop

Thanks and Regards.