After reading most posts about lock() and LockManager,I want to implement the lock mechanism with simplest way.I want only use a HashSet to stroe the locked record number,don't use a HashMap to store record number and clientid. The reason is:
1.I can implements the lock()/unlcok as the signature of requirement need:lock(int record) not LockManager.(int record,Object clientId).
2.As the important key:using HashSet can also fulfill the requirement "The unlock method simply
removes the lock from the specified record. If an attempt is made to unlock a record that has not
been locked by this connection, then no action is be taken" .
when method bookFlight excutes,the sequence is lock, read, modify, write, unlock .So when several clients requent the same record,Only one client can get the record's lock and only the
same client can unlock the record.Meanwhile 0ther client can't get the record's lock and perform
the unlock method.
My means is: the case as below can't occur.
A.lock(21);
...
B.lock(21);
...
A.lock(21);
My choise on lock have little extendable capability.But I think it is exacltly
satisfied with the requirement of FBN(Although LockManager is also a good choise).
please point out Whether I will lost mark when using the simple design.Did someone use the
similar design and pass the exam?