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 Calendar instance during parsing by StdDateFormat #1759

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

brenuart
Copy link
Contributor

@brenuart brenuart commented Sep 1, 2017

Addresses issue #1754

I reused the same strategy as for formatting.
A few comments tho:

  • TimeZone is reset on the calendar when used if the requested TZ does not match the one set on the reusable calendar.
  • Leniency is reset on the calendar as well every time the method _getCalendar is called. I did not add it as a method parameter as leniency is not contextual but set on the StdDateFormat itself.
  • As for the Locale we don't care as neither the parse or format method rely on it.

Should be ok I guess...

@Raniz85
Copy link

Raniz85 commented Sep 5, 2017

Doesn't this mean that multi-threaded deserialisation runs the risk of concurrently modifying the same calendar instance?

I think it would be a good solution to either use a resource pool or a ThreadLocal to ensure the thread has exclusive access to the Calendar instance.

@brenuart
Copy link
Contributor Author

brenuart commented Sep 5, 2017

Doesn't this mean that multi-threaded deserialisation runs the risk of concurrently modifying the same calendar instance?
The same question is valid for formatting too...
The former StdDateFormat applied the same pattern to create contextual instances of SimpleDateFormat (and its underlying Calendar). Everything was apparently construct with that clone() pattern in mind. How different is it here?

@Raniz85
Copy link

Raniz85 commented Sep 5, 2017

You're probably correct

@cowtowncoder
Copy link
Member

As per my notes on #1754, I think Calendar instance is actually cloned once per readValue() call and that reuse should be safe.

@cowtowncoder
Copy link
Member

.... but I still need to think of if and how to test possibility of concurrency issues. There is RaceCondition738Test which probably could serve as basis...

cowtowncoder added a commit that referenced this pull request Sep 6, 2017
@cowtowncoder cowtowncoder merged commit 8860630 into FasterXML:master Sep 7, 2017
@cowtowncoder cowtowncoder added this to the 2.9.1 milestone Sep 7, 2017
@cowtowncoder cowtowncoder changed the title Reuse Calendar instance during parsing Reuse Calendar instance during parsing by StdDateFormat Sep 7, 2017
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.

3 participants