On Oct 11, 11:06 pm, Chouser <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 11, 2008 at 9:50 PM, Mark McGranaghan <[EMAIL PROTECTED]> wrote:
>
> > I was just wondering what the intended use is for
> > TransactionalHashMap. Its a Java class defined in the Clojure source,
> > but not used anywhere else in the core code. How does this class fit
> > in with Clojure's PersistentHashMap and Java's ConcurrentHashMap?
>
> "rhickey added TransactionalHashMap, an implementation of
> java.util.ConcurrentHashMap that works in/with transactions"
>
> http://clojure-log.n01se.net/date/2008-08-01.html#09:36
>
> It looks to me like it's mutable, but all the data is actually stored
> in refs, so you can only do your mutations in a transaction:
>
> (def x
> (dosync
> (doto (clojure.lang.TransactionalHashMap.)
> (put :a 1)
> (put :b 2))))
>
Right, you _have_ to do any modifications in transactions, and you
_can_ issue reads in transactions to get snapshot consistency.
> So: thread safe, transactional, mutable ConcurrentHashMap.
It's much more powerful than a ConcurrentHashMap because it supports
atomic read-modify-write, atomic changes involving more than one item,
atomic changes involving more than one TransactionalHashMap etc. These
all fall out of its being transactional.
>Maybe it'd
> be useful for passing into Java libs?
It's useful anytime you find that a single ref holding a map of your
entire model has insufficient concurrency granularity. One option
would be a ref to a map of refs, the other is this
TransactionalHashMap.
With a ref to map of refs, any key insertions/removals still contend
for the root, and the client has to deal with refs as the values, and
you have a ref per value.
With TransactionalHashMap, key insertions/removals are distributed
across a set of bins, there are only Nbins refs, and Nbins acts as a
'knob' on the required granularity.
So, it will be very useful for larger Clojure programs, while
remaining interface-compatible with Java Map.
It's a first experiment in providing transactionally-mutable objects.
I'm sorry I haven't had time to write it up yet, but feel free to
experiment with it.
>
> Unfortunately you apparently can't print them in SVN 1063:
>
> java.lang.ClassCastException: clojure.lang.PersistentHashMap cannot be
> cast to java.util.Collection
Fixed in SVN 1064 - thanks for the report,
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---