tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: [OT - question] Limit user sessions in tomcat
Date Tue, 15 Dec 2009 19:12:30 GMT
Hash: SHA1


On 12/15/2009 1:52 PM, Ken Bowen wrote:
> Are there any standard techniques that a /developer/ of such a long 
> running proccess could apply to wrap the process in a cocoon which
> periodically updates a browser with (real) progress data, and at the
> same time, such updates are verifications that the socket is still
> live and the user hasn't gone away; if the user has gone away, that
> would be detected and the wrapper would kill the process??

Uh, probably :)

You'd probably want to do a few things:

1. Use a thread pool. This allows you to use your own threads to either
do the "real" work, or to manage the connections back to the client. I
recommend the former, and allowing Tomcat's threads to mostly sit idle
while the thread pool does your long-running business tasks.

2. All your tasks need to be gracefully interruptable. If you are doing
long-running database queries, then I'm not sure what you could do,
since you're just waiting on the server. If you want to limit query
time, there are methods in JDBC that allow you to at least request a
time limit on a query (see Statement.setQueryTimeout), though that won't
really help you out much because the query will simply be aborted after
a certain amount of time.

One way to make these tasks gracefully interruptable is to have them
periodically check a "stop" flag that is accessible by the task itself,
but also settable by, say, another thread. If the "stop" flag is ever
true, clean everything up and stop the task, preferably indicating to
the caller that the task was stopped instead of completing.

3. Have your webapp's code (running in the Tomcat-managed thread) poll
for activity. Something like this:

doGet() {

   Future future = new Task(); // be creative: see java.util.concurrent

   try {
     while(!future.isDone()) {
         try {
            Object result = future.get(1, TimeUnit.SECONDS);
         } catch (TimeoutException te) {
            response.flush(); // does this work?

            // now, just keep waiting...

     // send good response to client
   } catch (InterruptedException ie) {

   } catch (IOException ioe) {
      // client disconnected


   } finally {
      future.cancel(); // just in case

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


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

View raw message