my dog learned polymorphism
The moose likes Servlets and the fly likes Lifecycle of a HttpServletRequest instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Lifecycle of a HttpServletRequest instance" Watch "Lifecycle of a HttpServletRequest instance" New topic

Lifecycle of a HttpServletRequest instance

Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149

im writing a webapp that uses a chain of Servlets. Controlflow is managed via dispatching and everything works fine right now.

Out of curiosity - how long does this instance of HttpServletRequest live?

I didnt pursue the matter further, but during testing i had the Hash for the request object in the Log to trace the flow of parallel requests.

It seemed that Tomcat reuses this instance sometimes for Requests coming from the same Client.

As i said, it works, but im curious...

Any form of enlightenment is welcome :-)

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
It is up to the servlet container to create and manage HttpServletRequest and response objects. If the container wants to use a pool of request objects instead of creating new ones for each request, that is OK. Presumably it provides for clearing the old data before reuse.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

For the curious:

Search for the "recycle" method.
[ February 02, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Lifecycle of a HttpServletRequest instance
It's not a secret anymore!