On Fri, 2009-10-23 at 21:52 +0200, Paul Sandoz wrote:
> On Oct 23, 2009, at 9:22 PM, Chris Hubick wrote:
> > I run all Servlet API access through a ServletUtil class which
> > synchronizes all calls, which works fine directly under Tomcat. How
> > can I make this work under Jersey?
> >
> > Will finishing the port to the JAX-RS (HttpHeaders/UriInfo/etc) API
> > solve this, or will I have the same problem?
>
> If your resource classes are in the default per-request scope then
> there will be no issue as direct references of the JAX-RS classes you
> mention will be injected.
OK, so I finished enough of my conversion to the JAX-RS API to re-enable
threading, and immediately got a ConcurrentModificationException inside
java.util.ArrayList$Itr.next() when multiple threads (all inside the
request scope) try to simultaneously iterate (read-only) through the
List<Locale> returned by HttpHeaders.getAcceptableLanguages().
It appears as though the implementation at
com.sun.jersey.spi.container.ContainerRequest.getAcceptableLanguages()
(as well as other methods in that class) returns the result using a
non-thread-safe ArrayList, rather than say, a thread-safe Vector.
JAX-RS API thread safety would be a huge benefit to me, saving a lot of
ugly synchronization wrapper code around every call, like I needed for
Servlet API access. Is this a bug? I don't see anything in the
specification either way? Does that mean that, to work across JAX-RS
implementations, I am basically forced to synchronize myself? :(
Thanks!
--
Chris Hubick
mailto:chris_at_hubick.com
http://www.hubick.com/chris/