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

DecimalFormat is not thread-safe #237

Closed
drewnoakes opened this issue Feb 8, 2017 · 3 comments
Closed

DecimalFormat is not thread-safe #237

drewnoakes opened this issue Feb 8, 2017 · 3 comments

Comments

@drewnoakes
Copy link
Owner

We use DecimalFormat in fields in a few places. Turns out, surprisingly, that the class isn't thread-safe, thanks to this comment by @Nadahar.

Create a new one each time instead.

@drewnoakes
Copy link
Owner Author

Looking at the source from Oracle's JDK, I don't see a threading issue. In fact they synchronise some operations internally, and all state is on the stack it seems. However if the spec says it's not threadsafe, other implementations might not be.

@kwhopper
Copy link
Collaborator

kwhopper commented Feb 9, 2017

I don't know if it's desirable, but here's a short post on a ThreadLocal option:

http://jonamiller.com/2015/12/21/decimalformat-is-not-thread-safe/

Java isn't my forte so if the version you're targeting doesn't support it...

@drewnoakes
Copy link
Owner Author

@kwhopper hey sorry I didn't see your comment before pushing a fix for this. Looks like thread local support has been around since JDK 1.2, so I don't see a problem there.

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

No branches or pull requests

2 participants