• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to close all the port allocated by tomcat after a doGet() request

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a simple Servlet (stateless) which has a doGet() metohd. And I am using tomcat as my servlet engine.

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String arg = request.getParameter("p");

response.setStatus(HttpServletResponse.SC_OK);
return;

}





How can I make sure both Tomcat and the client calling that servlet's
doGet() to close all the ports (server and client) allocated upon the doGet() request.


Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to do that? Ports aren't "allocated" on a per-request basis. Are you meaning database connections perhaps?
 
Chris Corbyn
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean, if the client didn't send a "Connection: close" header in its request you want to force the connection to close anyway? Your question isn't very clear.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ying lam:
Hi,

I have a simple Servlet (stateless) which has a doGet() metohd. And I am using tomcat as my servlet engine.

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String arg = request.getParameter("p");

response.setStatus(HttpServletResponse.SC_OK);
return;

}





How can I make sure both Tomcat and the client calling that servlet's
doGet() to close all the ports (server and client) allocated upon the doGet() request.


Thank you.


Are you trying to say that no more requests should be allowed to the tomcat server ? Which would mean that the server's request port (say 8080) should be blocked ?

Or are you trying to say that once the request is serviced the connection should be severed ? Thats how HTTP works, each request is separate and you need something unique like a JSESSIONID in a cookie to identify a client with each request. You can also research the keep alive option in HTTP 1.1 and rephrase your question if needed
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the answer. Sorry for making my question not clear.

Let me rephrase my question again.

Tomcat listens on port 8080. But it needs to spawn another ports to handle client servlet requests so that it can go back to listen on port 8080.Right?

My question is how to make sure the ports which tomcat opens for handling client servlet requests are being closed correctly. So that I don't leaks ports as I run my servlet for a long time.

Thank you for any pointers.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ying lam:
Tomcat listens on port 8080. But it needs to spawn another ports to handle client servlet requests so that it can go back to listen on port 8080.Right?
I think that you may be confusing ports and threads. Containers will spawn new threads to habdle requests concurrently. These threads will get cleaned up automaticlly -- you don't need to do anything yourself.
[ September 02, 2007: Message edited by: Bear Bibeault ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
I think that you may be confusing ports and threads. Containers will spawn new threads to habdle requests concurrently. These threads will get cleaned up automaticlly -- you don't need to do anything yourself.


I think a new port is also allocated to the request so that the server can again go back and listen to port 8080 for new connection requests.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These low level issues are taken care of for you by the container.
Unless you're writing a container or some framework which eitehr manipulates or relies on non-standard behavior from the container, you should never need to concern yourself with them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!