aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About solving a deadlock problem in the exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "About solving a deadlock problem in the exam" Watch "About solving a deadlock problem in the exam" New topic
Author

About solving a deadlock problem in the exam

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
On Monkhouse's book, p 156. It says:


There are many solutions to prevent deadlocks, among them: ....

Ignore the problem. Seriously- is it a requirement of your assignment? Is there a possibility that attempting to handle this problem could result in you making a mistake....


If there is a deadlock when the program is execute, I don't think I can use exception handling to handle this problem.
When deadlock happens, the program hangs forever. If that is the case, I can only improve the code, but I cannot use try catch block to throw exceptions and let the rest of the program execute.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

What's your question/problem?


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
When deadlock happens in a program, the program hangs and it won't continue. The users need to terminate the program themselves.
Is there any way to use try catch block to handle deadlock, so that the program can continue?
(The Monkhouse book says it is still possible to handle deadlock. In the book, it always says that we can ignore this problem in the exam.)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

Here you'll find more info about handling a deadlock.

But for the assignment you should simple prevent a deadlock situation and then you don't have to worry about solving one.

Guillaume Drouet
Ranch Hand

Joined: Apr 16, 2012
Posts: 36
Hi !

Do you think that if we have validated our application without any deadlock issue it is still advised to implement a detection mechanism (like timeout for locking a record) ?

Thanks
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

I don't see what's the added value of adding extra code which will never be used. It only has drawbacks: increased complexity, more code to maintain, more code = more chance for bugs,... So, a deadlock detection mechanism is not needed at all!
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1464
    
    5

Hello Helen Ma,

IMHO, once deadlock happens in your code, it doesn't matter what you do or how you handle it - a MUST requirement is already broken (and you know what happens in that case )

A highly recommended option is to avoid deadlock at all costs. There is a really nice explanation given in Monkhouse book about how to achieve no-deadlock situation. Surprisingly, preventing deadlock is quite easy and desirable than detecting deadlock and then handling it (not to mention that you'll have to make sure that your deadlock-handling code itself is deadlock free )

I would suggest to go through approaches suggested by Monkhouse.

I hope it helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
Hi, Anayonkar,
Yes. I agree that deadlock avoidance is easier to handle than handling the code that hangs forever.
I remember Monkhouse suggests a very straightforward suggestion: make a thin client and let the server handle the business logic like retrieve and reserve DVD. If the client loses connection, it won't hold any locks. In the exam, I am thinking of building GUI on the client side application, make a facade to let the client to talk to the server remotely. Once multiple client requests are sent to the server, the server will hanle the request.
If I am using RMI, I don't think I need to create threads on the server to handle multiple client requests. To my knowledge so far, RMI itself will handle multiple client requests (multiple clients can talk to a single server and the RMI framework will handle the multiple threadings underneath the hood.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: About solving a deadlock problem in the exam
 
Similar Threads
Threads: deadlock or not?
About the dead lock
wait() and notifyAll() in static methods
Threads, wait, notify and deadlocks.
making multiple threads sleep and waking them up