• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic