openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey" <plins...@gmail.com>
Subject Re: EntityManager.lock not working
Date Fri, 22 Feb 2008 00:21:54 GMT
I believe that if you set the openjpa.ReadLockLevel appropriately, we
should only issue SELECT ... FOR UPDATE statements when a) the
FetchPlan's ReadLockLevel is set to 'write', or b) you issue an
em.lock() call.

-Patrick

On Thu, Feb 21, 2008 at 3:10 PM, Dain Sundstrom <dain@iq80.com> wrote:
> Does that make all locks pessimistic?  I wouldn't want to kill
>  performance just to get SELECT FOR UPDATE.
>
>  -dain
>
>
>
>  On Feb 21, 2008, at 2:18 PM, Patrick Linskey wrote:
>
>  >> If you want pessimistic locks in OpenJPA, you'
>  >
>  > ll need to set the openjpa.LockManager configuration setting to
>  > 'pessimistic'.
>  >
>  > -Patrick
>  >
>  > On Thu, Feb 21, 2008 at 2:16 PM, Patrick Linskey
>  > <plinskey@gmail.com> wrote:
>  >> If you want pessimistic locks in OpenJPA, you'
>  >>
>  >>
>  >>
>  >> On Thu, Feb 21, 2008 at 1:53 PM, Evan Ireland <eireland@sybase.com>
>  >> wrote:
>  >>> Dain,
>  >>>
>  >>> Sounds like you are wanting a pessimistic lock. The semantics
>  >>> of WRITE_LOCK are defined in optimistic terms in the spec.
>  >>>
>  >>> The JPA 2.0 expert group is looking into this. In the mean time,
>  >>> only non-portable apps can get this behaviour.
>  >>>
>  >>>
>  >>>
>  >>>> -----Original Message-----
>  >>>> From: Dain Sundstrom [mailto:dain@iq80.com]
>  >>>> Sent: Friday, 22 February 2008 9:50 a.m.
>  >>>> To: dev@openjpa.apache.org
>  >>>> Subject: EntityManager.lock not working
>  >>>>
>  >>>> I have a test case with two threads executing the following code:
>  >>>>
>  >>>>     public void run() {
>  >>>>         try {
>  >>>>             beginTx();
>  >>>>
>  >>>>             Employee david =
>  >>>> entityManager.getReference(Employee.class, pk);
>  >>>>             entityManager.lock(david, LockModeType.WRITE);
>  >>>>             entityManager.flush();
>  >>>>
>  >>>>             Assert.assertTrue(entityManager.contains(david));
>  >>>>
>  >>>>             Assert.assertEquals(david.getId(), pk);
>  >>>>             Assert.assertEquals(david.getFirstName(), "David");
>  >>>>             Assert.assertEquals(david.getLastName(), "Blevins");
>  >>>>             Assert.assertEquals(1000000.0, david.getSalary());
>  >>>>
>  >>>>             log("READ");
>  >>>>
>  >>>>             // wait for other threads to read
>  >>>>             try {
>  >>>>                 startBarrier.await(2, TimeUnit.SECONDS);
>  >>>>             } catch (Exception e) {
>  >>>>             }
>  >>>>
>  >>>>
>  >>>>             log("WRITE");
>  >>>>             david.setSalary(2000000);
>  >>>>
>  >>>>         } catch (Throwable throwable) {
>  >>>>             this.throwable = throwable;
>  >>>>         } finally {
>  >>>>             try {
>  >>>>                 commitTx();
>  >>>>             } catch (Throwable throwable) {
>  >>>>                 if (this.throwable == null) this.throwable =
>  >>>> throwable;
>  >>>>             }
>  >>>>         }
>  >>>>     }
>  >>>>
>  >>>> The first thread successfully reads the row and waits.  The
>  >>>> second throws an exception at the entityManager.flush()
>  >>>> command after the write lock.  I would assume that when I say
>  >>>> "give me a write lock"
>  >>>> OpenJPA would "give me a write lock".  Is there anyway to get
>  >>>> write lock in my application for single rows without having
>  >>>> to switch everything to SERIALIZABLE?
>  >>>>
>  >>>> -dain
>  >>>>
>  >>>
>  >>>
>  >>
>  >>
>  >>
>  >> --
>  >> Patrick Linskey
>  >> 202 669 5907
>  >>
>  >
>  >
>  >
>  > --
>  > Patrick Linskey
>  > 202 669 5907
>
>



-- 
Patrick Linskey
202 669 5907

Mime
View raw message