[concurrency-interest] question/bug in JCiP: Listing 4.12 ?
mboard182 at gmail.com
Wed Apr 7 17:34:40 EDT 2010
@Tim / @Joe - thanks for the (quite speedy...) reply. And quickly,
fantastic book, thank you; I own it & have gained significantly in both my
java and design skills.
Good to hear I wasn't crazy. @Joe, I would tend to agree with the "why that
when a safer one will do" sentiment - but many changes design improvements
would be required to support 'real-world' functionality, so IMHO here I feel
the example is muddled by the extraneous info. And unless you fully
understand the ramifications of your code, you can easily write
complex sequential code accidentally... Further, the sentence that
follows the listing ("PublishingVehicleTracker derives its thread safety
from delegation to an underlying ConcurrentHashMap") then seems to be
incorrect - doesn't the PVT "delegate" to the SafePoints, not the CHM?
So, as in my original post, it makes sense to me that a normal HashMap would
technically be OK here.
However, I am still uncertain with regards to visibility of the PVT's
internals. Somewhere in the heap the jvm has put a bunch of bits for the
internals of the 'locations' map - String (key) and handle (value) pairs,
Is visibility not an issue here because the PVT meets all the criteria for
an immutable object? (not just an "effectively immutable one)
-state cannot be modified (again, state is just key/value pairs here, which
aren't ever modified)
-all fields final
Or if it is only "effectively immutable" (why?) then is visibility
guaranteed if client code "safely publishes" it (ala JCiP page 52)?
On Wed, Apr 7, 2010 at 11:28 AM, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> PS - the java.util folks have a different phrase...
> On Apr 7, 2010 11:26 AM, "Joe Bowbeer" <joe.bowbeer at gmail.com> wrote:
> To rephrase your question: Can the locations map in PVT be implemented as a
> HashMap instead of a CHM, since it is read-only? I think the answer is yes.
> But as we in the Java.utility.cocurrent business say: Why use a HashMap when
> a ConcurrentHashMap will suffice?
> > On Apr 7, 2010 10:26 AM, "Mike" <mboard182 at gmail.com> wrote:
> > Hi,
> > In working through Ja...
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest