Hi,

The question might be silly but I don't really know what's in the
JAXBContext.

What is that bad in having a strong reference to it? I had the same issue
as kongar and my guess is that the cache is pretty much useless most of the
time because of the weak reference.

I will propose two solutions:
1- Use a SoftReference instead. It should be GCed but they tend to stick a
bit more around
2- Use a strong reference, and clear the cache in a ContextListener or so

WDYT?

Thanks,
Henri



On 23 July 2012 17:54, Daniel Kulp <[email protected]> wrote:

>
> Chaning to a strong reference would definitely NOT be good as things would
> never get garbage collected, jars would remain locked, etc....
>
> Couple thoughts for you:
>
> 1) If you can get a list of all the classes CXF detects and asks for the
> JAXBContext for (may just be the ObjectFactories), you could ask the
> JAXBContext for the same context and hold onto one stongly.
>
> 2) You could just create CXF client proxy or similar that would use the
> same
> context and hold onto that strongly.   You don't need to use it, just hold
> onto it so the context remains.
>
> Dan
>
>
>
> On Friday, July 20, 2012 05:49:48 PM kongar wrote:
> > Hi,
> >
> > I am currently trying to tune the performance of my CXF Client, and I
> > noticed that during Service creation, the JAXBContext keeps getting
> > created even if I'm hitting the same endpoint just with different
> > clients.  I looked into the CXF source, and I see that there is a caching
> > mechanism that's supposed to keep the context
> > (org.apache.cxf.common.jaxb.JAXBContextCache), but for one reason or
> > another, the cache lookup almost always fails.  It seems like since the
> > cache uses WeakReferences to hold the context, the context gets garbage
> > collected almost immediately and has to be recreated each time.  My calls
> > to the same endpoint happen only a few seconds apart so I'm a little
> > surprised that it gets collected that quickly.
> >
> > When I modified the JAXBContextCache (actually it's inner class
> > CachedContextAndSchemas) to use direct references instead of
> > WeakReference, this problem went away.  The caching worked as expected
> > and service creation went much faster.   But I would really prefer not to
> > modify the cxf source, so I'm wondering if there's something that I'm
> > missing or something that I can do so I can avoid rolling my own cxf
> > build?  I've looked into just keeping a reference of the JAXBContext in
> > my code to prevent it from being garbage collected, but it's pretty deep
> > into the cxf code and it doesn't seem like there was a clean way of doing
> > it.
>
> --
> Daniel Kulp
> [email protected] - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>

Reply via email to