Java Reference
In-Depth Information
SafePoint
in
Listing 4.11
provides a getter that retrieves both the
x
and
y
values at once
ues could change between the time one coordinate is retrieved and the other, resulting in a
caller seeing an inconsistent value: an (
x
,
y
) location where the vehicle never was. Using
SafePoint
, we can construct a vehicle tracker that publishes the underlying mutable state
without undermining thread safety, as shown in the
PublishingVehicleTracker
class
in
Listing 4.12
.
Listing 4.12. Vehicle Tracker that Safely Publishes Underlying State.