Project

Profile

Help

Saxon:thread attribute does not seem to result in multi-threading

Added by Paul Oprea about 10 years ago

Hi,

h2. Help appreciated, please, I don't seem to achieve multi-threading in applying an XSLT transformation.

h3. I'm not sure I am doing the correct thing but read doc and trying to implement a simple multi-threaded transformation.

Essentially the XSLT reads




	
	

    
	


So after reading some doc [here:[http://www.saxonica.com/documentation/extensions/attributes/threads.html]]

  • I am running my Java simple transformer from a command line, no debuggers that are supposed to disable multi-threading;
  • Not using any explicit configuration (as the default was supposed to be multi-threaded)
  • Tried redundant measures (setting Configuration explicitly to multi-threaded or including saxon:asynchronous - probably useless

So when I am connecting JConsole to it, I can see that the Thread count increases only by 1.

Java transformer below


package co.uk.dufrain.obiee.mds;

import net.sf.saxon.Configuration;

import java.io.File;
import java.io.IOException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class SimpleTransform implements Runnable{

    private final String sourcePath;
    private final String xsltPath;
    private final String resultDir;


    /**
     * SimpleTransform transformation method.
     * @param sourcePath - Absolute path to source xml file.
     * @param xsltPath   - Absolute path to xslt file.
     * @param resultDir  - Absolute path to the result file
     */
    public SimpleTransform(String sourcePath, String xsltPath, String resultDir) {
        this.sourcePath = sourcePath;
        this.xsltPath = xsltPath;
        this.resultDir = resultDir;
    }

    public static void main(String[] args) {
        if (args.length != 3) {
            System.err.println("Usage: java SimpleTransform xmlfile stylesheet outfile");
            System.exit(1);
        }

        try {
//            this is to enable having the option to connect JConsole before the actual execution begins  
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        //Set saxon as transformer.
        System.setProperty("javax.xml.transform.TransformerFactory",
                "net.sf.saxon.TransformerFactoryImpl");

        new Thread(
        new SimpleTransform(args[0], args[1], args[2])).start();

    }

    /**
     * @see Thread#run()
     */
    @Override
    public void run() {
        Configuration.newConfiguration().setMultiThreading(true);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        try {
            Transformer transformer =
                    tFactory.newTransformer(new StreamSource(new File(xsltPath)));

            transformer.transform(new StreamSource(new File(sourcePath)),
                    new StreamResult(new File(resultDir)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

h3. Am I doing something wrong here?

Thanks Paul


Replies (2)

RE: Saxon:thread attribute does not seem to result in multi-threading - Added by O'Neil Delpratt about 10 years ago

Hi,

Sorry for the late reply. I will be looking at your query to try and resolve it.

Just to check, please may you let me know the Saxon edition, version you are running and if you have a license file present in the class path. Multi-threaded processing is only available in Saxon-EE.

kind regards,

O'Neil

RE: Saxon:thread attribute does not seem to result in multi-threading - Added by Paul Oprea about 10 years ago

Hi,

I'm using 9.5.1EE and I thought the trial had included this license file (or if not, complain about not being able to find it :) )

Thanks Paul

    (1-2/2)

    Please register to reply