Sean, 

Sean Landis <sean.landis <at> gmail.com> writes:

> Thanks. So far so good. I happen to parameterize my Filter and Rep 
> with the request type so that the calls are typesafe. The downside 
> is that I have to create a special filter for every request type and
> that a single 'service' or Resource can't take more than one type of 
> request. I haven't found this to be a problem and it has added some
safety.

Interesting, but it makes sense because of the breakdown of resources ->
schemas. I think my breakdown is that a single Resource handles a
specific JAXBContext. The problem with this is that you have to
determine the type of object that you receive on the POST before you can
do any work after your unmarshall it. However, it allows for a single
Resource to handle the logic for a single object type (i.e. an Order
Resource to handle inserts, updates and deletes). This is just done
because my Resources are rather small, but I might like the idea of a
typesafe Resource, in which case I would refactor the common elements of
the Order Resource into separate Order class and re-use it.
  

> JAXBContexts are thread safe and appear to cache info so DO reuse
them.
> Marshallers and Unmarhsallers are NOT thread safe so recreate them or 
> do what I do and 'pool' them using ThreadLocal.

Thanks for the tips! I just started doing some profiling and noticed the
time it took to create a JAXBContext, so now I'm caching them as much as
possible. I didn't think about 'pooling' the Marshaller/Unmarshaller,
I'll have to give that some more thought.


Mitch


Reply via email to