|
Re: Owned Locks: msg#00006java.jsr.166-concurrency
Sorry I previously sent the response to Tim not the list. Hmm, I'm not sure how the room example applies and the OwnedLock example dosen't seem to allow for the owner of the lock to change overtime. The desired behavior is still a reentrant mutual exclusion the only problem is that I want to access the lock based on a owner not based the current thread. In the Java Transaction API [1] when implementing an XAResource there are number of methods which take an Xid which any locking needs to be based around. A rather contrived example is if I have an implementation of an XAResource which also has a method to update a variable pool based on an expression e.g. foo = foo++. This code is called as follows: resource.start(xid); result = resource.update("foo", "++"); resource.prepare(xid); // "foo" is now locked resource.commit(xid, false /*two phase commit*/); // "foo" is now unlocked and result is now filled in The implementation of the prepare and commit would look something like this: public StringBuilder update(String variable, String expression) { Variable v = variablePool.get(variable); StringBuilder result = new StringBuilder(); getCurrentTransactionContext().addUpdateRequest(v, expression, result); return result; } public void prepare(Xid xid) { // acquire the lock for(all update requests associated with this xid) { updateRequest.getVariable().getLock().lock(xid); } } public void commit(Xid xid, boolean onePhase) { if(onePhase) { prepare(xid); } // do the update for(all update requests associated with this xid) { updateRequest.doUpdate(); } // release lock for(all update requests associated with this xid) { updateRequest.getVariable().getLock().unlock(xid); } } There is more plumbing which I have omitted to associate the Xids with the update call. The problem is that the prepare which obtains any required locks and the commit doesn't have to be called on the same thread so the locking of foo cant be thread based. I don't mind that the owned lock doesn't implement the Lock interface and has an extra owner parameter. I already have an implementation of the owned locks, I was just hoping I could leverage the built in locking. [1] http://java.sun.com/products/jta/ Tim Peierls wrote: Richard Zschech wrote:
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Owned Locks, Tim Peierls |
|---|---|
| Next by Date: | RE: Owned Locks, David Holmes |
| Previous by Thread: | Re: Owned Locks, Tim Peierls |
| Next by Thread: | RE: Owned Locks, David Holmes |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |