tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Interrupting tomcat threads.
Date Thu, 19 Jul 2007 22:09:50 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kief,

keif wrote:
> Christopher Schultz-2 wrote:
>> I assume you mean that you want to cancel an already-running thread /for a
>> given user/ if a
>> second one comes in.
>  
> Yes, that is correct - I'd like to process a single request at a time per
> session. The reason for that is that I have to maintain some state
> information in the session. This state information is then used to
> recieve/send dynamic updates to the client via ajax requests.

So, multiple simultaneous AJAX requests are considered illegal?

> If I let two requests run together then I might have a situation where the
> second request finishes and sends a response, then the first request
> processing finishes and updates the session state. In this case the user
> will see data on screen for the second request, but the server will have
> state for the first request.  

This is generally called a "race condition" and is okay if it is
tolerable for your user interface. I would recommend a healthy mix of
synchronization (to prevent data corruption) and serialization (that is,
putting events in order... not writing object data to streams) to solve
this problem, rather than trashing threads on the server side.

I would also recommend vetoing the /second/ request, rather than
canceling the first request when a second one comes in. You should have
each synchronous request report some kind of "success" state, so that
when the second request fails, the UI doesn't update inappropriately.

> Your reply has some valueable pointers, could you recommend any references
> for the subject of threading and perhaps the way it relates to tomcat? 

Nope, and you shouldn't rely on any information that you /can/ find by
reading Tomcat source code. Instead, stick to conforming to the servlet
spec (which basically says NOT to do what you are doing) and ignore
Tomcat's implementation.

> The way I understand is that I should not be touching the container provided
> thread(request thread), but instead spawn a new thread once the request
> comes in and manage it with Filter that you proposed.

You should not have to spawn any threads or anything like that. You'll
only make your life more complicated by doing that.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGn+Eu9CaO5/Lv0PARAnj7AKC+R6XY2Yxe6J7VprwHSeGJf6lnMQCgrcMo
XUdLMdvlbujhsUPtILewA+c=
=FhJv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message