You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Melanie.Bats@UTBM.fr" <Me...@utbm.fr> on 2005/04/05 10:46:51 UTC

[transaction.locking]Want to lock intervals

Hi,

I want to use the ReadWriteLockManager and ReadWriteLock on interval. To
facilitate the operation on interval I use the package xxl.core.util.Interval1D.

The LockManager works well if I try to get and release locks on same interval.
For example, a first thread T1 get a ReadLock on the interval I[1, 122] and then
a second thread T2 try to obtain a WriteLock on I, T2 will wait until T1 release
its lock on I.

The LockManager does not work well in this case : a first thread T1 get a
ReadLock on the interval I1[1 , 5] and then a second thread T2 try to obtain a
WriteLock on I2[4 , 7], T2 will obtain is lock and we will have incompatible
locks on the intersection of I1 and I2 [4, 5].

The problem is that I1 and I2 are two different objects for the LockManager.

Is that possible to modify the ReadWriteLock and the ReadWriteLockManager, in
order to determine when intervals intersect. It must verify the compatibility of
the lock or wait for the release when it is incompatible ?

I expect I am clear, if not ask me for details :o)

Thanks for your help,

Mel

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by "Melanie.Bats@UTBM.fr" <Me...@utbm.fr>.
Hi,

Selon Oliver Zeigermann <ol...@gmail.com>:

> When a lock on an interval is tried you first will have ot check for
> all other intersecting ones without actually acquiring locks on them.
> Only if this works you can acquire the lock on the desired interval.
> Otherwise you will wait for them to be freed.

I am trying to implement this solution. To do this, I need to get all the owners
for each locks.

How could I get them ? I get all the locks like this :

Interval1D iIntervalTmp = new Interval1D(aInterval);
Iterator iIter = mRWULockManager.getLocks().iterator();
for (ReadWriteLock iInterval = null; iIter.hasNext(); )
{
 iInterval = (ReadWriteLock) iIter.next();

 if(iInterval.getLockLevel(iInterval.getOwner())!= 0)
  {
   System.out.println("Owner " + iInterval.getOwner() +
                     (Interval1D) iInterval.getResourceId());
   }
}

Here my problem is that I just get the first owner for each resource...I don't
understand how to get all the owners.

> Does this make sense?

Sure and I am trying to implement it ;o)

Thanks again for your help,

Mel

> On Apr 5, 2005 11:24 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> > Hi,
> >
> > Selon Oliver Zeigermann <ol...@gmail.com>:
> > > I suppose you pass the interval as the resourceId, right?
> >
> > Yes exactly.
> >
> > > The problem is that normally a single locks gets assigned to a
> resourceid. I
> > > do not think there is an easy solution if  your intervals are not
> > > discrete.
> >
> > They are not discrete. There is infinity number of values inside an
> interval ;(
> >
> > > But if they are you could just enumerate all values as
> > > resourceIds and try to lock check each and every of them. This would
> > > of course require writing your own lock manager,  but that shouldn't
> > > be too hard.
> >
> > To find if intervals intersect I use the functions of the package
> > xxl.core.util.Interval1D. If intervals intersect I must wait that thread
> release
> > locks on the interval. Using this I don't need to test all the values.
> >
> > Do you have ideas ? Is it possible to implement this just by modifying the
> > ReadWriteLockManager ?
> >
> > Thanks,
> > Mel
> >
> > > On Apr 5, 2005 10:46 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr>
> wrote:
> > > > Hi,
> > > >
> > > > I want to use the ReadWriteLockManager and ReadWriteLock on interval.
> To
> > > > facilitate the operation on interval I use the package
> > > xxl.core.util.Interval1D.
> > > >
> > > > The LockManager works well if I try to get and release locks on same
> > > interval.
> > > > For example, a first thread T1 get a ReadLock on the interval I[1, 122]
> and
> > > then
> > > > a second thread T2 try to obtain a WriteLock on I, T2 will wait until
> T1
> > > release
> > > > its lock on I.
> > > >
> > > > The LockManager does not work well in this case : a first thread T1 get
> a
> > > > ReadLock on the interval I1[1 , 5] and then a second thread T2 try to
> > > obtain a
> > > > WriteLock on I2[4 , 7], T2 will obtain is lock and we will have
> > > incompatible
> > > > locks on the intersection of I1 and I2 [4, 5].
> > > >
> > > > The problem is that I1 and I2 are two different objects for the
> > > LockManager.
> > > >
> > > > Is that possible to modify the ReadWriteLock and the
> ReadWriteLockManager,
> > > in
> > > > order to determine when intervals intersect. It must verify the
> > > compatibility of
> > > > the lock or wait for the release when it is incompatible ?
> > > >
> > > > I expect I am clear, if not ask me for details :o)
> > > >
> > > > Thanks for your help,
> > > >
> > > > Mel
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by Oliver Zeigermann <ol...@gmail.com>.
Locking a node will require locking of all ancestors as well. Not
quite sure of a read lock is sufficient of if you will need write
locking all ancestors when you write lock a node. However, this is not
specific to commons tx, but a more general question.

Oliver

On Apr 6, 2005 2:21 PM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> Hi,
> 
> Selon Oliver Zeigermann <ol...@gmail.com>:
> 
> > I suppose what you want is some sort of hierarchical lock? Like if a
> > parent is locked the children are locked as well? Is that true?
> 
> Yes it is something that looks like this.
> 
> Do you have some ideas that could help me to implement this ?
> 
> Thanks
> Mel
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by "Melanie.Bats@UTBM.fr" <Me...@utbm.fr>.
Hi,

Selon Oliver Zeigermann <ol...@gmail.com>:

> I suppose what you want is some sort of hierarchical lock? Like if a
> parent is locked the children are locked as well? Is that true?

Yes it is something that looks like this.

Do you have some ideas that could help me to implement this ?

Thanks
Mel

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by Oliver Zeigermann <ol...@gmail.com>.
On Apr 6, 2005 2:13 AM, Mélanie Bats <me...@utbm.fr> wrote:
> Hello,
> 
> Oliver Zeigermann a écrit :
> 
> > All this would be in the lock manager and would not require changes to
> > the lock classes.
> 
> In order to understand correctly how to implement the solution to my
> problem, I looked at the implementation of the GenericLock class. I have
> a few questions about it.
> 
> As far as I understand, a GenericLock is associated to a resourceId (the
> object _being_ locked, which in my problem will be an interval). When
> ones want to get a lock, either read or write, on this resourceId, the
> acquire() method is called. The ownerId is the object that _wants_ the
> lock (in my problem, will be a Thread). Am I right ?

Yes.

> I have the feeling that a GenericLock object has to be associated to an
> other object (the resourceId), for which it manages the lock. For
> example, if I define a MessageMailbox object, I could associate a
> GenericLock to it to handle the locking issues.

Yes.

> However, in my case, it is a bit different. The objects I am accessing
> are the nodes of an XML tree. However, I don't want to lock each node
> independently, but instead allocate dynamically intervals of nodes being
> accessed.
> 
> Using the interval as the resourceId does not seem to be the right
> solution : the object being protected by the lock is not the interval
> itself, but rather the nodes covered by the interval. I'm not sure if
> it's all clear, but I think this small detail changes pretty much
> everything.

I suppose what you want is some sort of hierarchical lock? Like if a
parent is locked the children are locked as well? Is that true?

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by Mélanie Bats <me...@utbm.fr>.
Hello,

Oliver Zeigermann a écrit :

> All this would be in the lock manager and would not require changes to
> the lock classes.

In order to understand correctly how to implement the solution to my 
problem, I looked at the implementation of the GenericLock class. I have 
a few questions about it.

As far as I understand, a GenericLock is associated to a resourceId (the 
object _being_ locked, which in my problem will be an interval). When 
ones want to get a lock, either read or write, on this resourceId, the 
acquire() method is called. The ownerId is the object that _wants_ the 
lock (in my problem, will be a Thread). Am I right ?

I have the feeling that a GenericLock object has to be associated to an 
other object (the resourceId), for which it manages the lock. For 
example, if I define a MessageMailbox object, I could associate a 
GenericLock to it to handle the locking issues.

However, in my case, it is a bit different. The objects I am accessing 
are the nodes of an XML tree. However, I don't want to lock each node 
independently, but instead allocate dynamically intervals of nodes being 
accessed.

Using the interval as the resourceId does not seem to be the right 
solution : the object being protected by the lock is not the interval 
itself, but rather the nodes covered by the interval. I'm not sure if 
it's all clear, but I think this small detail changes pretty much 
everything.

Any suggestion ?

Thanks for your help,

Mélanie

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by Oliver Zeigermann <ol...@gmail.com>.
Not quite sure if this will work, but you could store all intervals
there currently is a lock on in a resource manager. As soon as the
lock is freed, the intervals gets removed and to every interval a lock
is associated.

When a lock on an interval is tried you first will have ot check for
all other intersecting ones without actually acquiring locks on them.
Only if this works you can acquire the lock on the desired interval.
Otherwise you will wait for them to be freed.

All this would be in the lock manager and would not require changes to
the lock classes.

Does this make sense?

Oliver


On Apr 5, 2005 11:24 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> Hi,
> 
> Selon Oliver Zeigermann <ol...@gmail.com>:
> > I suppose you pass the interval as the resourceId, right?
> 
> Yes exactly.
> 
> > The problem is that normally a single locks gets assigned to a resourceid. I
> > do not think there is an easy solution if  your intervals are not
> > discrete.
> 
> They are not discrete. There is infinity number of values inside an interval ;(
> 
> > But if they are you could just enumerate all values as
> > resourceIds and try to lock check each and every of them. This would
> > of course require writing your own lock manager,  but that shouldn't
> > be too hard.
> 
> To find if intervals intersect I use the functions of the package
> xxl.core.util.Interval1D. If intervals intersect I must wait that thread release
> locks on the interval. Using this I don't need to test all the values.
> 
> Do you have ideas ? Is it possible to implement this just by modifying the
> ReadWriteLockManager ?
> 
> Thanks,
> Mel
> 
> > On Apr 5, 2005 10:46 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> > > Hi,
> > >
> > > I want to use the ReadWriteLockManager and ReadWriteLock on interval. To
> > > facilitate the operation on interval I use the package
> > xxl.core.util.Interval1D.
> > >
> > > The LockManager works well if I try to get and release locks on same
> > interval.
> > > For example, a first thread T1 get a ReadLock on the interval I[1, 122] and
> > then
> > > a second thread T2 try to obtain a WriteLock on I, T2 will wait until T1
> > release
> > > its lock on I.
> > >
> > > The LockManager does not work well in this case : a first thread T1 get a
> > > ReadLock on the interval I1[1 , 5] and then a second thread T2 try to
> > obtain a
> > > WriteLock on I2[4 , 7], T2 will obtain is lock and we will have
> > incompatible
> > > locks on the intersection of I1 and I2 [4, 5].
> > >
> > > The problem is that I1 and I2 are two different objects for the
> > LockManager.
> > >
> > > Is that possible to modify the ReadWriteLock and the ReadWriteLockManager,
> > in
> > > order to determine when intervals intersect. It must verify the
> > compatibility of
> > > the lock or wait for the release when it is incompatible ?
> > >
> > > I expect I am clear, if not ask me for details :o)
> > >
> > > Thanks for your help,
> > >
> > > Mel
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by "Melanie.Bats@UTBM.fr" <Me...@utbm.fr>.
Hi,

Selon Oliver Zeigermann <ol...@gmail.com>:
> I suppose you pass the interval as the resourceId, right?

Yes exactly.

> The problem is that normally a single locks gets assigned to a resourceid. I
> do not think there is an easy solution if  your intervals are not
> discrete.

They are not discrete. There is infinity number of values inside an interval ;(

> But if they are you could just enumerate all values as
> resourceIds and try to lock check each and every of them. This would
> of course require writing your own lock manager,  but that shouldn't
> be too hard.

To find if intervals intersect I use the functions of the package
xxl.core.util.Interval1D. If intervals intersect I must wait that thread release
locks on the interval. Using this I don't need to test all the values.

Do you have ideas ? Is it possible to implement this just by modifying the
ReadWriteLockManager ?

Thanks,
Mel

> On Apr 5, 2005 10:46 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> > Hi,
> >
> > I want to use the ReadWriteLockManager and ReadWriteLock on interval. To
> > facilitate the operation on interval I use the package
> xxl.core.util.Interval1D.
> >
> > The LockManager works well if I try to get and release locks on same
> interval.
> > For example, a first thread T1 get a ReadLock on the interval I[1, 122] and
> then
> > a second thread T2 try to obtain a WriteLock on I, T2 will wait until T1
> release
> > its lock on I.
> >
> > The LockManager does not work well in this case : a first thread T1 get a
> > ReadLock on the interval I1[1 , 5] and then a second thread T2 try to
> obtain a
> > WriteLock on I2[4 , 7], T2 will obtain is lock and we will have
> incompatible
> > locks on the intersection of I1 and I2 [4, 5].
> >
> > The problem is that I1 and I2 are two different objects for the
> LockManager.
> >
> > Is that possible to modify the ReadWriteLock and the ReadWriteLockManager,
> in
> > order to determine when intervals intersect. It must verify the
> compatibility of
> > the lock or wait for the release when it is incompatible ?
> >
> > I expect I am clear, if not ask me for details :o)
> >
> > Thanks for your help,
> >
> > Mel
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [transaction.locking]Want to lock intervals

Posted by Oliver Zeigermann <ol...@gmail.com>.
Hi Mel,

I suppose you pass the interval as the resourceId, right? The problem
is that normally a single locks gets assigned to a resourceid. I do
not think there is an easy solution if  your intervals are not
discrete. But if they are you could just enumerate all values as
resourceIds and try to lock check each and every of them. This would
of course require writing your own lock manager,  but that shouldn't
be too hard.

Oliver 

On Apr 5, 2005 10:46 AM, Melanie.Bats@UTBM.fr <Me...@utbm.fr> wrote:
> Hi,
> 
> I want to use the ReadWriteLockManager and ReadWriteLock on interval. To
> facilitate the operation on interval I use the package xxl.core.util.Interval1D.
> 
> The LockManager works well if I try to get and release locks on same interval.
> For example, a first thread T1 get a ReadLock on the interval I[1, 122] and then
> a second thread T2 try to obtain a WriteLock on I, T2 will wait until T1 release
> its lock on I.
> 
> The LockManager does not work well in this case : a first thread T1 get a
> ReadLock on the interval I1[1 , 5] and then a second thread T2 try to obtain a
> WriteLock on I2[4 , 7], T2 will obtain is lock and we will have incompatible
> locks on the intersection of I1 and I2 [4, 5].
> 
> The problem is that I1 and I2 are two different objects for the LockManager.
> 
> Is that possible to modify the ReadWriteLock and the ReadWriteLockManager, in
> order to determine when intervals intersect. It must verify the compatibility of
> the lock or wait for the release when it is incompatible ?
> 
> I expect I am clear, if not ask me for details :o)
> 
> Thanks for your help,
> 
> Mel
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org