This was 8.7 and I got a stack trace for two threads which were waiting on a Map function.  However, let me get fresh stack traces and get back to you.

I am using getParameterDoc to build an XML file for input.  The dynamic context uses a URI resolver.  XQRecord doesn’t do anything but associate a timestamp for debugging.

 

                  XQRecord record = queries.get(xqPath);

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

                        if (log.isDebugEnabled())

                              log.debug("compiling xq:" + xq);

                        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());

                  final QueryUpdate upd = new QueryUpdate(state);

                  dynamicContext.setParameter("upd", upd);

                  dynamicContext.setParameter("_operationType", args.get("_operationType"));

                  dynamicContext.setParameter("user", state.getUser());

                  Document doc = getParameterDoc(args);

                  dynamicContext.setParameter("args", doc);

                  dynamicContext.setParameter("state", state);

                  dynamicContext.setParameter("spaceFileService", state.getFileService());

                  // add services

                  for (Map.Entry<String, Service> entry: services.entrySet())

                        dynamicContext.setParameter(entry.getKey(), entry.getValue());

                  dynamicContext.setURIResolver(new SourceResolver(state));

                  StringWriter out = new StringWriter();

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

                  if (upd.hasUpdates())

                        state.getFileService().update(upd);

                  if (log.isDebugEnabled()) {

                        log.debug("\n"+Transform.getString(new DOMSource(doc),false));

                        log.debug(out.toString());

                  }

                  return out.toString();

 

      private Document getParameterDoc(Map<String, String> args)

            throws SpaceException {

            Document doc = Transform.getBuilder().newDocument();

            Element mapE = doc.createElement("args");

            for (Map.Entry<String,String> e: args.entrySet()) {

                  String key = e.getKey();

                  Element argE = createElement(doc, key);

                  if (argE != null) {

                        if (key.startsWith("_") && !key.equals("_id")) {

                              Parser p = new Parser(e.getValue());

                              appendParm(doc, argE, p);

                        } else {

                          Text text = doc.createTextNode(e.getValue());

                          argE.appendChild(text);                            

                        }                            

                        mapE.appendChild(argE);

                  }

            }          

            doc.appendChild(mapE);

            return doc;

      }

 

 

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 6:02 PM
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] multithreading and XQueryExpression

 

I can't see any reason why that should need synchronizing, assuming that XQRecord isn't doing any trickery behind the scenes.

What were the symptoms of failure?

Which Saxon release is this?

Are there any hooks such as URIResolvers or ErrorListeners involved?

How does the query get its source input?

Are you using the DOM anywhere?

Michael Kay
Saxonica

On 20/02/2013 23:15, Boysen, Pete [ITACD] wrote:

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 

 




------------------------------------------------------------------------------
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