dev@jax-ws.java.net

Re: Thread safety of the JAX-WS API

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 03 Oct 2006 17:46:37 -0700

Doug Kohlert wrote:
> I am not sure this should be addressed in the spec as another
> implementation might be much faster at creating a Service instance.

You shouldn't think in terms of whether something can be fast or not.
You should think in terms of striking the right balance between the
usability and the implementation freedom.

If requiring a thread safety is going to restrict the implementation
choice significantly enough that it outweighs the user benefit, then you
don't want to say anything. If it does overall help users, you should.

Take a look at Template in JAXP. It does require that a Template object
be immutable and thread-safe, so that it allows multiple threads to
create Transformer from a single Template object. If this is not
required, then the user would have to have parse a XSLT stylesheet in
every thread, which is a usability problem (as well as performance
problem.) In comparison, implementing a Template in a thread-safe way is
very easy. Hence that requirement.


Similar thing applies to JAX-WS Service object. I don't think requiring
a service to be thread-safe is going to restrict the implementation
choice at all --- at most you have to put synchronized keywords
everywhere, but that's it.

So in terms of striking the right balance, I think there's a significant
gain in usability/performance if we can require Service to be
thread-safe, and very little to lose.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com