I am so happy that I foregot to say thanks to JavaRanch.
Because I've learned so lots from JavaRanch.
---------------------------------------------
My lock implementation is very simple.
1. I uses a static Random long seed initialized once JVM started, as a seed of looked cookie generation.
2. I uses a map to store all current available mapping of locked record and cookie. The key of the entry is a record number, the value mapped to the key (record) is the cookie held by a client.
3. I uses the object locked of the map to synchronize the record lock and unlock process.
4. I notify all
thread waiting on the object locked of map only after unlocked a record successfully.
5. Make sure that the process of checking if a record is locked by other thread or checking if the record is exist, before locked a record, should be keep in synchronized block.