tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Struts application used as a web service (large number of sessions)
Date Wed, 16 Feb 2011 16:34:43 GMT
Ok thanks, your explanations were very useful. I'll do what you suggested, 
i.e. not create a session for the Struts actions matching the web service 


André Warnier <> 
2011-02-15 06:02 PM
Please respond to
Tomcat Users List <>

Tomcat Users List <>

Re: Struts application used as a web service (large number of sessions) wrote:
> Hello everybody,
> I wrote a Struts application deployed on a Tomcat server that is used as 
> web service. What I see is that for every request sent by the client 
> applications a new session is created; I guess this is because there's 
> JSESSIONID cookie sent with the request. Could someone tell me if it's 
> terribly inefficient for the server to have to create a new session for 
> every request? I could reduce the session timeout to the minimum, but 
> application is also used by interactive users so the session timeout 
> to have a reasonable value.
HttpSession (HttpRequest.)getSession() :
  Returns the current session associated with this request, or if the 
request does not 
have a session, creates one.

HttpSession :

A session is created when there is a call to getSession().
No call to getSession(), no session.

In the big scheme of things, from the above descriptions, I would tend to 
think that a 
"session object" is not something trivial, so creating one when you don't 
need it is 
probably indeed quite inefficient.
(And then the session has to be stored somewhere, which will involve 
serialization, I/O 
etc..; and then some background task still has to periodically go clean up 
these useless 

 From your description, it seems as if there are two types of usage of the 
same application :
- a usage by real users, which does require a session
- a usage as a web service, which does not require a session
   (because these are one-off calls, probably)

I don't know Struts at all, but is it possible to distinguish the two 
types of usage, and 
bypass the getSession() call when the application is used as a web service 

Otherwise, would it be possible to set up two instances of your 
application ?
Such as :
/webapp1 : used by interactive users
/webapp2 : used by web service clients
and remove the getSession() call in the one used as a web service ?

Now again, inefficiency is a relative concept.
If your server is 50% idle anyway, you do not really want to spend a lot 
of time bringing 
it to 60% idle.

To unsubscribe, e-mail:
For additional commands, e-mail:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message