I'm not 100% sure if the Compiler and ProcessorFactory are thread safe. We fix issues as they come up and try our best, but I'm not sure we guarantee thread-safety. For example, there are definitely known issues if you use the set*() functions. The newer with*() functions were added to deal with these potential issues and should be used instead.
The DataProcessor is thread-safe, and we work hard to make sure it stays that way, since this is the thing that does most of the work. So every DataProcessor parse() or unparse() call can definitely be made in different threads without a problem. The ScalaXMLInfosetOutputter (as well as most of the other InfosetOutputters) are stateful, and so should not be shared among different threads, but they can be reused by calling the reset() function. I would recommend one InfosetOutputter per thread and call reset() inbetween uses. Or just create a new one each time parse/unparse is needed--these should be pretty lightweight to allocate. In general, I would recommend a workflow of creating a unique Compiler/ProcessorFactory/DataProcessor for each unique schema that you want to parse/unparse data with. Once you have the DataProcessor, throw away the Compiler/ProcessorFactory and cache and reuse that DataProcessor anytime you need to parse/unparse data using that schema. And then create/reset the InfosetOutputter as mentioned above. - Steve On 8/5/20 2:26 PM, Patrick Grandjean wrote: > Hi, > > I am looking to optimize applications that use Apache Daffodil and would like > to > know which classes or functions are thread-safe, reusable, can be cached in a > singleton, etc. For instance, I believe that ScalaXMLInfosetOutputter is > reusable since it has a reset() function. Here is a list of > classes/functions/instances I am currently using: > - Daffodil.compiler() > - ProcessorFactory > - ProcessorFactory.onPath(String) > - DataProcessor > - ScalaXMLInfosetOutputter > > I would like to avoid having to instantiate each class at every call. > Otherwise, > what are the common optimizations that can be done when using Apache > Daffodil's > Java/Scala API? > > Patrick. >