SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:
If you have deadlock on client or server side, you will fail. If client A is updating say record 1 (meaning your server is locking record 1), and client B comes along and also try to update record 1, then client B wait until client A finishes his update and then when B actually try to update would prompt an error saying record 1 is already booked preventing client B to update.
K. Tsang wrote:
Deadlock issue is really on the server side if you are using a service layer. If you expose lock() and unlock() methods to the client then it becomes client side.
K. Tsang wrote:
... In my case if the same client does call lock(1) twice, that thread will deadlock waiting for itself. Of course we shouldn't expect that.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Roel De Nijs wrote:
If an automatic test-program on the server tries to lock the same record twice, an IllegalStateException will be thrown. So no deadlock and an exception being thrown because it's abusive use of my API.
Same remark if a client (or test-program) tries to lock another record already owning the lock on another record.
If the specified record is already locked by a different client, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked. When a client tries to lock the record while already holding its lock may lead to a deadlock. It is the responsibility of the client to avoid it.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Roel De Nijs wrote:
If other coders passed with a similar approach I don't think it was luck. But I don't know of a rock solid solution to prevend deadlock with a lockCookie, besides mentioning in javadoc and choices.txt
And because you mention it in your choices.txt you certainly have thought about it, so that's a good point. If you don't mention it at all, it seems to the accessor that you don't know deadlock could happen (and maybe losing some points in the locking section)
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
cheers,
D
cheers,
D