[J2EE] Legal to access the HttpServletRequest concurrently ?

B

Ben_

Hello,

I have identified an issue where the current diagnostic is that there would
be concurrent access to the HttpServletRequest attributes.

I'm wondering if it is legal or not to pass the HttpServletRequest object
and access it concurrently (I haven't found references in the spec yet). And
if not illegal, is it safe or not ?

Thanks.
 
A

Anton Spaans

Ben_ said:
Hello,

I have identified an issue where the current diagnostic is that there would
be concurrent access to the HttpServletRequest attributes.

I'm wondering if it is legal or not to pass the HttpServletRequest object
and access it concurrently (I haven't found references in the spec yet). And
if not illegal, is it safe or not ?

Thanks.

I don't know if it is possible or not, but why would you have more than one
thread per http-request?
Do you have your own daemon threads running inside the web-server, that may
access incoming http-requests as well? If so, why? There may be better
solutions (no concurrency handling needed).

I think it depends on the web-server implementation you're running
(Tomcat/Resin/etc) whether concurrency is handled or not.
I would not bet on it, though, since each http-request should be handled by
only one thread (the thread servicing the http-request).
-- Anton.
 
B

Ben_

I couldn't figure out exactly yet, but based on the dumps, one guess is
concurrent access to the request attributes (which is a HashMap). Another is
modification of the attributes (remove) while iterating over the collection.

For threading, as you mentionned, there should be one-to-one mapping (one
HTTP request = one HttpServletRequest = one thread).

It's not an application of mine so I couldn't make a code review yet.

And until then, I'm already looking for pointers as to the legality or best
practices about sharing / accessing / modifying the HttpServletRequest
attributes object in the course of a ServletRequest. It can be a lengthy
path in an MVC pattern (servlet / some utility code / servlet / JSP /
another JSP / etc).

My feeling is that it's not illegal but rather unsafe. Which is yours as
well, but I'd like to find literature about this (spec, post, article, blog,
etc).

Thx.
 
H

HalcyonWild

Ben_ said:
For threading, as you mentionned, there should be one-to-one mapping (one
HTTP request = one HttpServletRequest = one thread).

Is your servlet implementing SingleThreadModel
My feeling is that it's not illegal but rather unsafe. Which is yours as
well, but I'd like to find literature about this (spec, post, article, blog,
etc).

It is unsafe I suppose. Suppose, your servlet is executing, and
dispatches the request at the end of the processing, with the request
and response, to a JSP. Now when jsp page is submitted, request will
have a new set of parameters. If your another thread is still using the
request, there are chances of it finding changed /inconsistent data, if
it still has not finished execution, and the user is fast enough.

Try something else.
 
B

Ben_

Is your servlet implementing SingleThreadModel

No.
It is unsafe I suppose. Suppose, your servlet is executing, and
dispatches the request at the end of the processing, with the request
and response, to a JSP. Now when jsp page is submitted, request will
have a new set of parameters. If your another thread is still using the
request, there are chances of it finding changed /inconsistent data, if
it still has not finished execution, and the user is fast enough.

Mmmh, yes, it's a possible weird cause. I'll think at it. Thx.
Try something else.

What do you mean ?
 
H

HalcyonWild

Ben_ said:
What do you mean ?

This.
Can you do your work without the thread. If not, consider using
Thread.join() in your scenario, so that the servlet thread waits for
the other thread to finish.
 
R

Raymond DeCampo

Ben_ said:
Hello,

I have identified an issue where the current diagnostic is that there would
be concurrent access to the HttpServletRequest attributes.

I'm wondering if it is legal or not to pass the HttpServletRequest object
and access it concurrently (I haven't found references in the spec yet). And
if not illegal, is it safe or not ?

Thanks.

Wild guess: are you using Oracle's application server? Some versions
have a bug where the request parameters from other requests are shared
across requests. There is a work-around, let me know if you need more
information.

Ray
 
B

Ben_

Hello,

No, it's WebSphere, but it's an interesting pointer nevertheless. I'll check
their bug list.

Thx.
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top