db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerNativeImpl.java
Date Thu, 16 Sep 2004 11:21:17 GMT
arminw      2004/09/16 04:21:17

  Modified:    src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerNativeImpl.java
  Log:
  merge with branch,
  use keyword 'volatile' to make decrement of
  static long counter an atomic operation
  
  Revision  Changes    Path
  1.20      +9 -13     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java
  
  Index: SequenceManagerNativeImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerNativeImpl.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SequenceManagerNativeImpl.java	8 Sep 2004 22:11:04 -0000	1.19
  +++ SequenceManagerNativeImpl.java	16 Sep 2004 11:21:17 -0000	1.20
  @@ -98,9 +98,11 @@
   
        2. Problem is that generated oid (by Identity column)
        must not begin with 0.
  +
  +     Use keyword 'volatile' to make decrement of a long value an
  +     atomic operation
        */
  -    private static long tempKey = -1;
  -    private static Object dummy = new Object();
  +    private static volatile long tempKey = -1;
   
       public SequenceManagerNativeImpl(PersistenceBroker broker)
       {
  @@ -280,16 +282,10 @@
       {
           /*
           arminw:
  -        AFAIK, when using primitive long it's not guaranteed that "--value" is an atomic
  -        operation in JVM, so synchronize it
  +        workaround for locking problems of new objects
  +        We need unique 'dummy keys' for new objects before storing.
  +        Variable 'tempKey' is declared volatile, thus decrement should be atomic
           */
  -        synchronized(dummy)
  -        {
  -            /*
  -            workaround for locking problems of new objects
  -            We need unique 'dummy keys' for new objects before storing
  -            */
  -            return --tempKey;
  -        }
  +        return --tempKey;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message