Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Async servlets and thread-safety

Hi,

On Mon, Jan 28, 2013 at 3:38 PM, Nils Kilden-Pedersen <nilskp@xxxxxxxxx> wrote:
> I'm wondering though. Even with async, your request is never handled by more
> than a single thread at a time, and one must presume that there are built-in
> synchronization points (locking or volatile) that ensures memory visibility,
> and if so, the servlet writer should not need to do anything differently.

Well... no :)

There always are inherent race conditions between the thread that
"suspends" the request and the one that "resumes" it; those threads
will run your code, so yes we do things properly in the container, but
the rest is up to you.
There always are inherent race conditions between the thread that
times out a "suspended" request and the one that "resumes" it.

As I said, it's not impossible. But you have to be careful of what you
do, and yes your code may be accessed concurrently (well this was true
also before: HttpSession may always be accessed concurrently), and the
degree of carefulness depends on what you do in your code.
Patterns like suspend/complete are safer, suspend/dispatch less safe.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.


Back to the top