This compiles the expression once and then executes it.  Multiple threads can run this code. I originally did not have the synchronized section which is where I ran into trouble.

 

                  XQRecord record = queries.get(xqPath);

                  if (record == null || (debugXQ && record.before(f.lastModified()))) {

                        StaticQueryContext staticContext = new StaticQueryContext(Transform.getConfiguration());

                        xqin = getResourceAsStream(xq);

                        if (xqin == null)

                              throw new SpaceException("missing " + xq);

                        XQueryExpression exp = staticContext.compileQuery(xqin, "UTF-8");

                        record = new XQRecord(exp, f.lastModified());

                        queries.put(xqPath, record);

                  }

                  DynamicQueryContext dynamicContext = new DynamicQueryContext(Transform.getConfiguration());

                  synchronized(record) {

                        StringWriter out = new StringWriter();

                        record.getExp().run(dynamicContext, new StreamResult(out), null);

                  }

 

Pete Boysen(pboysen@iastate.edu)

Information Technology Services

209 Durham

(515)294-6663

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: Wednesday, February 20, 2013 5:01 PM
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] multithreading and XQueryExpression

 

In that thread, the user was making the mistake of using the XsltTransformer (in your case it would be the XQueryEvaluator) in more than one thread. The XQueryExpression is thread-safe but the XQueryEvaluator is not.

If that isn't your problem, please supply more information about what you are doing and what the symptoms of failure are.

Configuration.setMultiThreading() is a red herring here; it enables or disables internal optimizations that use multiple threads. I doubt very much that this is relevant to your problem.

Michael Kay
Saxonica

On 20/02/2013 22:19, Boysen, Pete [ITACD] wrote:

The documentation for XQueryExpression says it is thread-safe but I am running into the same issues as http://markmail.org/message/bjluqky3ratrbqoy

when the same expression is run by separate threads at the same time.  Is this resolved by Configuration.setMultiThreading(true) or do I have to synchronize on the XQueryExpression?

 

 

Pete Boysen(pboysen@iastate.edu)

Information Technology Services

209 Durham

(515)294-6663

 




------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb




_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help