Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

is TransformerFactory threadsafe ?

Help
ageissler
2010-06-28
2012-10-08
  • ageissler
    ageissler
    2010-06-28

    Hello,

    I use Saxon Transformer Transformerfactory.newInstance().newTransformer() for
    transforming DomSource to Writer.

    My Question is :

    Can I make the TransformerFactory static so that only one Factory creates
    Transformers for different threads ?

    Regards, Andre

     
  • Michael Kay
    Michael Kay
    2010-06-28

    It should be perfectly safe to use a TransformerFactory concurrently in
    different threads, provided of course that you don't try setting its
    properties such as the ErrorListener and URIResolver.

    However, I'm not sure it's wise to make it static. Underneath the Saxon
    TransformerFactory is the Saxon Configuration, and this owns all kinds of
    resources like loaded schemas, the namepool, and so on. While it's fine to
    share these across threads in a single application, at some point you may want
    to run multiple applications concurrently within the same JVM, and you will
    want to have the flexibility to unload these resources when the application
    finishes, or to have different schemas and namepools in different
    applications.