Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

[J2EE] Legal to access the HttpServletRequest concurrently ?

Thread view: 
Ben_ - 29 Sep 2005 13:01 GMT
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.
Anton Spaans - 29 Sep 2005 17:12 GMT
> Hello,
>
[quoted text clipped - 6 lines]
>
> 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.
Ben_ - 29 Sep 2005 21:09 GMT
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.
HalcyonWild - 29 Sep 2005 22:05 GMT
> 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.
Ben_ - 30 Sep 2005 06:39 GMT
> 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 ?
HalcyonWild - 30 Sep 2005 10:50 GMT
> > Try something else.
>
> 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.
Raymond DeCampo - 08 Oct 2005 03:03 GMT
> Hello,
>
[quoted text clipped - 6 lines]
>
> 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

Signature

XML is the programmer's duct tape.

Ben_ - 08 Oct 2005 08:03 GMT
Hello,

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

Thx.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.