From: Keats <ke...@ea...> - 2003-07-24 22:40:33
|
Sounds great. I'll have to read up on this! ----- Original Message ----- From: "Brian Goetz" <br...@qu...> To: "Keats" <ke...@ea...> Cc: <web...@li...> Sent: Thursday, July 24, 2003 6:13 PM Subject: Re: [Webmacro-devel] ContextTool replacement and thread-safety > > >The question is, would such an approach reduce the cost of synchronization > >to the point where it is worth giving up the quick, unsynchronized lookups? > >Should we maintain a separate table for preconfigured, thread-safe tools? > >Or is hot deploy/undeploy really important? > > > >Brian, I know you are expert in this area, so please chime in. > > Short answer: the ConcurrentHashMap class from Doug Lea's util.concurrent > gives you the best of both worlds. It is a thread-safe Map that avoids > locking on the common code path. It is blazingly fast, and a masterpiece > of coding. If I hadn't audited the code myself, I wouldn't believe it. > > The common case, a lookup for an object already in the map, succeeds > without locking. So in the case where you load up the map once at startup, > its no slower than HashMap. (And, unlike other similar attempts at the > same result, this one is actually thread-safe, under both the old and new > Java Memory Models.) > > So basically, with CHM, its a non issue. (I'm going to rip out all the > fancy cache-management crap and replace it with a ConcurrentHashMap.) > |