Remove @Synchronized annotation from Rfc3339DateJsonAdapter
.
#1842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Rfc3339DateJsonAdapter
can convert a nullableDate
object to a JSON string and vice versa.If a system attempts to concurrently serialize or deserialize large objects containing many
Date
objects or collections of those large objects, there could be contention across threads and delays due to synchronization.Synchronization evaluation
1. fromJson
fromJson
constructs and uses a localCalendar
instance and does not use any sharedDateFormat
, thus it should not need to be synchronized.2. toJson
toJson
callsDate.formatIsoDate
extension method, which provides a (mutable)Date
object to localCalendar
instance.The underlying code for
calendar.time = this
simply gets theLong
time value from theDate
object which is a thread-safe operation.Therefore, synchronized execution shouldn't be needed for
toJson
.Changes
@Synchronized
annotation fromfromJson
andtoJson
inRfc3339DateJsonAdapter
to make it usable concurrently.Outcome
Lower contention across threads & synchronization overhead can improve efficiency and compute resource utilization in multi-threaded environments such as in backend servers.
Benchmark
Setup
Outcome