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

Reuse the calendar instance used during formatting #1750

Merged
merged 1 commit into from
Aug 26, 2017

Conversation

brenuart
Copy link
Contributor

See #1749

The idea is to reuse the calendar instance used for formatting using the same strategy as for DateFormat instances.
A new _calendar instance field is added to hold the calendar once initialised. However, java.text.DateFormat already has a protected calendar field that is not used. I wonder if we should use that one instead of creating another...

@cowtowncoder
Copy link
Member

The main/only concern here is the life-cycle of StdDateFormat: is an instance created (via clone()) for serialization (in which case it is thread-safe by being only used from a single thread) or shared.
I should know it having rewritten code very recently... :-D

So I'll have to go over code again.

Another possibility, if instances were shared, would be to use AtomicReference for "leasing" instance.

@cowtowncoder
Copy link
Member

Ok, so syncing is bit of a mess but yes, instance IS clone()s for serialization purposes so this should be safe without further complications.
I think it'll be worth further refactoring for 3.0 -- I am thinking of actually splitting read/write aspects, maybe? -- but for now this'll work.

@cowtowncoder cowtowncoder merged commit 299e2b0 into FasterXML:master Aug 26, 2017
@cowtowncoder cowtowncoder added this to the 2.9.1 milestone Aug 26, 2017
@brenuart brenuart deleted the gh1749 branch August 28, 2017 09:08
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

Successfully merging this pull request may close these issues.

2 participants