I've been hacking the tree methods in Node recently, triggered by the need to construct multiple subtrees during area tree construction, cobbling them together as necessary. In the original version, I was able to synchronize on the Node's containing Tree instance, but that is no longer feasible, as Nodes may be free-floating.

My first change was to synchronize the methods which had previously been synchronized on the Tree, but I realized that such synchronization of methods in inner classes probably only synchronized on the actual inner class instance, not on the containing class instance. Does anyone have any knowledge of this?

It also occurred to me that optional synchronization might be a good idea, allowing a common synchronization object to be passed to the Node constructor. An alternative was to allow optional synchronization, but to synchronize on the affected Node object. On the construction of any particular Node, a boolean can be passed indicating the need for synchronization.

To implement this, I use the Node or the containing Node (in the case of inner classes) as the synchronization object. So iteration operations on the Tree (like those of PreOrder or PrecedingSibling) and bulk operations (like copySubTree) end up synchronizing on each Node during the traversal. This has the advantage that operations which occur relative to any given Node (like those of PrecedingSibling) can occur in parallel with activities in other parts of the tree. The disadvantages include the large number of possible synchronizations, and an unknown incremental risk of deadlock.

Does anyone have experience with such issues?

Peter
--
Peter B. West <http://www.powerup.com.au/~pbwest/resume.html>



Reply via email to