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:10:53 GMT
arminw      2004/09/16 04:10:52

  Modified:    src/java/org/apache/ojb/broker/util/sequence Tag:
                        OJB_1_0_RELEASE SequenceManagerNativeImpl.java
  Log:
  use keyword 'volatile' to make decrement of
  static long counter an atomic operation
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.18.2.2  +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.18.2.1
  retrieving revision 1.18.2.2
  diff -u -r1.18.2.1 -r1.18.2.2
  --- SequenceManagerNativeImpl.java	8 Sep 2004 22:08:50 -0000	1.18.2.1
  +++ SequenceManagerNativeImpl.java	16 Sep 2004 11:10:52 -0000	1.18.2.2
  @@ -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