Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf | Is TemplateEngine.process thread-safe operation?

I use thymeleaf template engine to build request to SOAP service. The class that perform sending looks like this:

import java.io.StringReader;
import java.util.*;
import javax.xml.transform.stream.*;

import org.springframework.ws.client.core.WebServiceTemplate;

import org.thymeleaf.*;
import org.thymeleaf.context.*;
import org.thymeleaf.templateresolver.*;

public class SomeService 
{
    private final TemplateEngine templateEngine;
    private final WebServiceTemplate webServiceTemplate;

    public RetrieveServiceThymeleafBased() {
        webServiceTemplate = new WebServiceTemplate();
        webServiceTemplate.setDefaultUri("http://some.path/to/soap/service");

        ITemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateEngine = new TemplateEngine();
        templateEngine.addTemplateResolver(templateResolver);
    }

    public void sendMessage(String orderNumber) {
        Context params = new Context();
        params.setVariable("CreateDateTime", new Date());
        params.setVariable("GUID", UUID.randomUUID());
        String xmlContent = templateEngine.process("template.xml", params);

        StreamSource source = new StreamSource(new StringReader(xmlContent));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    }
}

I know that webServiceTemplate.sendSourceAndReceiveToResult - is thread-safe operation, But I can't find this kind of information about templateEngine.process

Question : Is templateEngine.process a thread-safe operation or not

like image 464
CAMOBAP Avatar asked Apr 11 '14 07:04

CAMOBAP


1 Answers

Yes, it is. TemplateEngine objects are designed to be used in highly-concurrent environments without issues (I hope! ;)).

Disclaimer, per StackOverflow rules: I'm Thymeleaf's author.

like image 177
Daniel Fernández Avatar answered Nov 15 '22 20:11

Daniel Fernández