6 Replies Latest reply on Nov 15, 2007 1:45 AM by spennec

    "Manually" acquiring a lock on a node

    spennec

      Hello,

      In my project, we cache the result of a computation. This computation takes quite some time (5-6 seconds) to be done.

      When the definition of the computation is modified, the node corresponding to the modified computation is removed. At that time, the computation is updated, and its new result is cached.

      What I would like to do is get a lock on the computation's node (or parent), remove the node, update the value to cache and put the new value in the node. Only after that the node would be unlocked.

      Is there a way to do this?

      Thanks :)

        • 1. Re:
          aditsu

          Just do all those things within a transaction. Locks should be acquired automatically.

          Adrian

          • 2. Re:
            manik

            If you want to specifically get a write lock on the parent node as well, look at:

            http://labs.jboss.com/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/TreeCache/en/html_single/index.html#d0e2123

            and look for the LockParentForChildInsertRemove attribute.

            • 3. Re:
              spennec

              Thanks for your reply :-)

              Should I use a specific Node Locking Scheme to ensure that behaviour? At the moment, I use Optimistic scheme (and, consequently, no Isolation Level).

              • 4. Re:
                spennec

                Here's what's happenning at the moment:

                A transaction:
                - put some data in the cache.

                Another transaction:
                - modify its definition -> remove() is called
                - update its value -> put() is called with the new value

                The problem is that if I call get() on that node between the remove() and the put(), I still obtain the old value, but shouldn't I obtain null??

                • 5. Re:
                  manik

                  LockParentForChildInsertRemove works with both optimistic and pessimistic locking.


                  You won't receive a null in your above scenario since the write (in this case, the remove() call) will not be visible to other threads until the transaction commits.

                  • 6. Re:
                    spennec

                    Manik,

                    Thanks for the info on LockParentForChildInsertRemove, I'm going to try that.