SCJP, SCJD, SCWCD, SCBCD
SCJP, SCJD, SCWCD, SCBCD
5. For the Locking part, I do NOT specify the functions provided in the SUN interface as synchronized in order to avoid the chances for auto fail. Instead, I perform synchronization for each function. I used Vector as the locker. Maybe this makes me lost points, however, some people who use HashMap results the same as me. I do check whether the record is locked before each access, and I do notify all threads after the lock operation(lock and unlock) completes. I really wonder why so many people score 44/80 in this part, I have sent an email to SUN about this issue.
Locking
======
The implementation of the Services book method in ServicesImpl is the only user of the locking API. I specified a contract in the Javadoc that calls for any potential users of the locking API to invoke lock/process/unlock as a sequence within the context of a single method call which guarantees it will happen within a single thread of execution. When lock is invoked, a check is made to see if the Contractor already has been locked by another thread. If it has, the current thread will wait until notified that it has been unlocked. If not, a Lock object is created that has a reference to the current thread and it is put in the locking Map with the Contractor as the key. The protected processing operation is performed and then the Lock is removed from the Map and destoyed by the unlock method call. It is vital that any exception that occurs during processing is caught and rethrown after the Contractor has been unlocked. Deadlock is prevented by specifying a locking order to be used by programmers.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
1a. Avoid deadlock risks: never call out to a foreign controller (object)
from within a synchronized block.
Ken probably can confirm that he did not do this, he did not lock a complete collection to operate on one element or record.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
I specified a contract in the Javadoc that calls for any potential users of the locking API to invoke lock/process/unlock as a sequence within the context of a single method call which guarantees it will happen within a single thread of execution.
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Jacques<br />*******<br />MCP, SCJP, SCJD, SCWCD
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |