persistence@glassfish.java.net

RE: pessimistic locking

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 12 Feb 2007 15:36:46 -0500

Hello Scott,
    Given the particularly arbitrary nature of this method combination we will want to go a different route. Given the available APIs the best way to support pessimistic locking on the lock API is to have configurable class level pessimistic locks. For example the fastest feature to develop would be to add a persistence.xml property that would cause any lock obtained on a particular class to be a pessimistic lock.
    The feature would be relatively quick to implement but given the status of the 9.1 branch (feature complete?) may have to wait until an update.
    Using this particular combination could be a SpecJ only feature but customers would be better served by a practical feature.
--Gordon


-----Original Message-----
From: Scott.Oaks_at_Sun.COM [mailto:Scott.Oaks_at_Sun.COM]On Behalf Of Scott
Oaks
Sent: Monday, February 12, 2007 2:46 PM
To: persistence_at_glassfish.dev.java.net
Subject: pessimistic locking


The SPEC organization is in the process of developing a JPA-based
benchmark based on the CMP 2.1 implementation of SPECjAppServer 2004.
Certain objects used in that benchmark are concurrently modified by
multiple clients simultaneously; in order to score well on the
benchmark, pessimistic locking must be used on those entities.
Otherwise, the time spent rolling back and retrying the operation (often
multiple times) is quite excessive.

Realizing that pessimistic locking in the JPA spec is non-portable, SPEC
intends to go this route: the highly-contended objects will be obtained
this way:

        Customer c = em.getReference(Customer.class, 1);
        em.lock(c, LockModeType.WRITE);

And have the appserver vendor configure (though deployment descriptors
or something else that doesn't modify the code) the locks obtained that
way to be pessimistic locks. They have checked several JPA
implementations, all of whom say that they will be able to support such
a feature (including, apparently, Toplink, though AFAIK, that doesn't
apply to the subset of toplink in glassfish).

This is a feature we would need quite soon; preferably in 9.1 or at
least in an update soon after. What is the feasibility of doing so?

-Scott