File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes [URLyBird]Why dead lock? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "[URLyBird]Why dead lock?" Watch "[URLyBird]Why dead lock?" New topic
Author

[URLyBird]Why dead lock?

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi all,

I have finished my LockManager coding. While only one client booking, nothing abnormal. But more than one client booking the same room, the server application will deadlock as:
normal: only one client booking


Please help me.

[Andrew: Deleted methods - refer to SCJD FAQ for why.]
[ April 13, 2006: Message edited by: Andrew Monkhouse ]

SCJP 1.4 SCJD
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello,
Your lockManager class is strongly coupled with your data access class.
My advice is try to make a lockManager implementation without dependencies, hidden behind an interface, this way your application will be more maintainable.
Why the lockManager has to know when a record is in deleted state?
Regards


SCJP, OCMJD, OCMJEA
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi Oricio,


Why the lockManager has to know when a record is in deleted state?

If record 2 is already locked by clientA. Now clientB try to lock record 2, but find that record 2 has already in lockMap. Then clientB wait. A few milliseconds later, clientA deleted record 2 and unlock. Then record 2 was moved from lockMap. At the same time clientA is waked and find that record 2 is not in lockMap, then clientA lock record 2 and do some execution. While in fact, record 2 is no longer valid and can not be lock and executed.
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi all,

Because RMI created threads are not easy to control, I give up using wait and notifyAll. My choice now is sleep and test have already bone with my expected result. So everything seems easy using sleep. But I not sure whether using sleep will ail score?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: [URLyBird]Why dead lock?