Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is Template (render) thread safe? #287

Open
zacMode opened this issue Oct 12, 2023 · 2 comments
Open

Is Template (render) thread safe? #287

zacMode opened this issue Oct 12, 2023 · 2 comments

Comments

@zacMode
Copy link

zacMode commented Oct 12, 2023

Hi, i'm new to this library (and ANTLR), but looking to add it to a project. I'm trying to understand how a Template instance should be used. Is it safe to parse a liquid string once and then use the single Template instance concurrently to render different strings?

e.g.

Template template = Template.parse(" hello, {{ name }}");

final ExecutorService executorService = Executors.newCachedThreadPool()
for (int i  = 0; i < 10_000; i ++) {
  executorService.submit(()-> template.render(Map.of("name", randomName())));
}

Thanks!

@msangel
Copy link
Collaborator

msangel commented Oct 13, 2023

We made a lot of effort in moving forward to that, but still, no.
Each render call redefine internal templateContext field, so it is not safe yet to use this in multi-threaded env.

Keeping this ticket open until it will be thread-safe.

@msangel
Copy link
Collaborator

msangel commented Oct 14, 2023

Also errors() method depends on the context, so we cannot do it local/parameter. it should be field.
image

Using Thread local for that is problematic. (we want know errors as long as it could)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants