how you will create new record by reusing deleted entry? as of now you are not allowing to lock deleted record. If you don't lock deleted record (e.g. 11) two threads can create new record at same record i.e. 11 .
Thanks for your post, Ken.
Agree but creating the record does not require locking. I will explain.
Let's say CLIENT_1 calls Data.create method.
The Data class will call database.create method
My database class has cached deleted records. So the database.create will:
1. Lock the cache.
2. check if there is deleted record in cache. If it is it will use the recNom for writing the record. If not it will use the last record +1.
3. synchronize on the database and write the new record.
4. delete entry from deleted records cache.
5. Unlock the cache and return recNo.
CLIENT_2 will try to create record by calling the same Data.create that will call database.create.
Now it will stop waiting for the lock to be released from the 1st step. After cache is released it will not contain deleted record used by the first client. Therefore this client will use another record or new one - step 2.
Did I miss anything ?