Session management in tomcat.

Hi guys,

How would i configure my application server(TOMCAT) to only allow 10 concurrent sessions at a time.
For every connection after that there should be a proper message indicating maximum sessiions reached.
 
^ Technically Tomcat is not an application server but a servlet container. I do not think you can limit the number of sessions but I guess you are trying to limit the number of concurrent requests. See here and here.
 
pinga123 said:
Hi guys,

How would i configure my application server(TOMCAT) to only allow 10 concurrent sessions at a time.

For every connection after that there should be a proper message indicating maximum sessiions reached.

maxThreads will limit the maximum number of active connections to the value you specify; acceptCount will be the additional buffer. But this doesn't mean it will limit to 10 sessions only, this is only to configure tomcat to handle these many requests at a single time slice.

There are two ways u can limit the max. active session, either you use a Servlet Filter (more generic) or a Controller Servlet with a variable in the application scope to hold the current no. of active sessions. Both ways u can redirect to an alert page to show the desired message. Filters will take some time to figure out, a controller servlet will be much easier to implement .. for this simply do the following :

(i) check for session.isNew() in calling JSP, if true then set an attribute with a value to identify this in the servlet

(ii) define a private static integer variable for the controller servlet to hold the current active sessions, initialize to 0

(ii) in doPost() or doGet(), check the value of the session variable; if it matches new session then check if the above variable is <10; if true then increment and carry on, else simply redirect to your error page.

This method is not limited to applications servers, but the application itself. Also limiting the total active http connection doesn't mean limiting the no. of sessions .
 
deathvirus_me said:
maxThreads will limit the maximum number of active connections to the value you specify; acceptCount will be the additional buffer. But this doesn't mean it will limit to 10 sessions only, this is only to configure tomcat to handle these many requests at a single time slice.

There are two ways u can limit the max. active session, either you use a Servlet Filter (more generic) or a Controller Servlet with a variable in the application scope to hold the current no. of active sessions. Both ways u can redirect to an alert page to show the desired message. Filters will take some time to figure out, a controller servlet will be much easier to implement .. for this simply do the following :

(i) check for session.isNew() in calling JSP, if true then set an attribute with a value to identify this in the servlet
(ii) define a private static integer variable for the controller servlet to hold the current active sessions, initialize to 0
(ii) in doPost() or doGet(), check the value of the session variable; if it matches new session then check if the above variable is <10; if true then increment and carry on, else simply redirect to your error page.

This method is not limited to applications servers, but the application itself. Also limiting the total active http connection doesn't mean limiting the no. of sessions .
Thank you very much for the explanation. Being a novice in jsp i may take some time to actually code it in my application . I would highly appreciate if you give some sample code implementing the above scenario.
 
^^ hehe okie, i think i can write down little code snippets sometime later, but you get to do the whole thing yourself ..

--- Updated Post - Automerged ---

ibose said:
^ Does this method really prevent the number of concurrent sessions from going beyond 10 ?
hmm a controller servlets can be used to limit a lot of thing, maximum number of active sessions can be traced and limited. This is often done in cases the application is quite heavy on resource utilization and must handle a specific number of clients at a time only. The moment u reach the limt, simply redirect to error page and invalidate any active client session,...
 
deathvirus_me said:
^^ hehe okie, i think i can write down little code snippets sometime later, but you get to do the whole thing yourself ..

--- Updated Post - Automerged ---


hmm a controller servlets can be used to limit a lot of thing, maximum number of active sessions can be traced and limited. This is often done in cases the application is quite heavy on resource utilization and must handle a specific number of clients at a time only. The moment u reach the limt, simply redirect to error page and invalidate any active client session,...

^^ Yes, at the application context level, this method may be used. I was looking for the invalidate session part :) .. do not forget to decrement that count when you invalidate a session :bleh:

Alternatively at the application server level, as rightly pointed out one can use a Servlet Filter
 
Back
Top