"Stein M. Hugubakken" wrote:
> Keith Visco wrote:
> >
> >
> > 1. Cache the descriptors!
> >
> > import org.exolab.castor.xml.ClassDescriptorResolver;
> > import org.exolab.castor.xml.Unmarshaller;
> > import org.exolab.castor.xml.util.ClassDescriptorResolverImpl;
> >
> > ClassDescriptorResolver cdr = new ClassDescriptorResovlerImpl();
> >
> > ...
> >
> > Unmarshaller unm = new Unmarshaller(...);
> > unm.setResolver(cdr);
> >
> > By reusing the same ClassDescriptorResolver any time you create an
> > Unmarshaller instance, you will be reusing the existing class
> > descriptors previously loaded.
> >
>
> Is this thread-safe?
That really depends on the implementation of the ClassDescriptorResolver
I suppose. It's been a while since I last looked into thread-safety
issues with Castor, so I can't say for sure if our default implementation
is thread safe or not. However if someone is aware of a problem, please
report it via bugzilla!
I can't really guess as to what thread-related issues would arise,
perhaps the possibility of loading a class / class descriptor twice? If
two threads detect that a class descriptor hasn't been loaded they both
load the class descriptor, one will overwrite the other one, but I don't
really see that as an issue.
Of course we'd have to analyze that code a bit more to determine possible
problem areas. Are you aware of any?
For assurance one could always wrap the default ClassDescriptorResolver
using a custom thread-safe implementation that synchronizes the calls, or
write their own ClassDescriptorResolver from scratch. Another solution
would be to just make sure to use a new ClassDescriptorResolver for each
thread.
Either way, as long as you are reducing the number of times needed to
search + load classes, you'll speed up performance.
I do recommend only caching the class descriptor resolver for one
particular mapping or schema however, because you could possibly run into
issues where similar element names return the wrong class descriptor,
especially ones where no namespaces are used.
--Keith
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev