Please explain SRV.2.3.3.3 Thread Safety clause

M

me.curious

SRV.2.3.3.3 Thread Safety
Implementations of the request and response objects are not guaranteed
to be thread safe. This means that they should only be used within the
scope of the request handling thread. References to the request and
response objects must not be given to objects executing in other
threads as the resulting behavior may be nondeterministic.

My question is does a scenario arise often in practice? And if so,
could you let me know when.
 
H

hiwa

does a scenario arise often in practice?
I only depends on you own (bad) coding practice.
Basically, request and response are arguments passed
to the servlet methods. You should keep them as they are.
 
C

curious

That's right,
But can u please further explain what practices can be bad in this
context?
That what all a developer should take care regarding this "CLAUSE" so
that his coding does not become bad.
 
T

Thomas Hawtin

SRV.2.3.3.3 Thread Safety
Implementations of the request and response objects are not guaranteed
to be thread safe. This means that they should only be used within the
scope of the request handling thread. References to the request and
response objects must not be given to objects executing in other
threads as the resulting behavior may be nondeterministic.

My question is does a scenario arise often in practice? And if so,
could you let me know when.

You'd be surprised at what some people will put in the session scope.

Tom Hawtin
 
J

John C. Bollinger

curious said:
That's right,
But can u please further explain what practices can be bad in this
context?

The text you quoted in the first place describes the constraints pretty
well. You must not expose the request or response object to view by
other threads. That could happen by storing one of them in the session
or application, by assigning one to a static or instance variable of a
servlet, by making one visible to a thread that you start yourself,
etc.. The list is infinite, but those are some of the most likely abuses.
That what all a developer should take care regarding this "CLAUSE" so
that his coding does not become bad.

A servlet (including JSPs) should not expose the request or response it
is handling to other threads (see above). Furthermore, a servlet should
never rely on (or hold) a request or response past the end or servicing
the corresponding request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top