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

[Question] Is the Parser class thread safe? #44

Closed
gayashanbc opened this issue Aug 15, 2019 · 3 comments
Closed

[Question] Is the Parser class thread safe? #44

gayashanbc opened this issue Aug 15, 2019 · 3 comments

Comments

@gayashanbc
Copy link

Can someone tell me whether the Parser class is thread-safe?
If I'm using the Parser class in multiple places, what is the best we to do it?

@bpossolo
Copy link
Contributor

It should be safe yes.
I've been using it in a thread-safe manner for a while.
There is this outstanding issue which needs to be addressed though.

Just create the Parser instance on app startup then pass the reference around.
You can have multiple threads invoking the parser.parse() method
or if you're using a dependency injection framework, you can bind an instance of the Parser in Singleton scope

@anttibrax
Copy link

I have read the code with this in mind and could not find anything that wasn't thread safe from the Parser class. It uses java.util.regex.Pattern, which is thread safe and does not expose the Matchers outside of method scope.

@bpossolo
Copy link
Contributor

Gonna close this issue since it’s been resolved. Thanks @anttibrax

ShanePark added a commit to ShanePark/dutypark that referenced this issue Feb 19, 2023
Parser is thread-safe, so share it.
ua-parser/uap-java#44

response time 700ms -> 200ms
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

3 participants