aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes lingering wait()/notify() and deadlock doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "lingering wait()/notify() and deadlock doubt" Watch "lingering wait()/notify() and deadlock doubt" New topic
Author

lingering wait()/notify() and deadlock doubt

Alexander Danilou
Greenhorn

Joined: May 08, 2009
Posts: 28
Hi, can somebody help me with this?
A call to wait()/notify() will NOT prevent a deadlock - true of false?

I think it should be false, because when calling wait() thread releases the lock, so deadlock can be prevented.
But according to K&B the answer is true..
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13399

I think it should be false, because when calling wait() thread releases the lock, so deadlock can be prevented.


Just because a method releases a lock -- doesn't mean that it is a mechanism that can be used to prevent deadlocks. Can you explain how the method can be used to prevent deadlocks?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2586

As Henry wrote, it cannot be used as a mechanism "to prevent deadlocks". But it "may" prevent deadlocks on some situations. In my view, this question cannot be accurately answered without having more details on it. Found your other topic.

Devaka.


Author of ExamLab - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13399

But it "may" prevent deadlocks on some situations.


In theory, this may be true. In practice, I have never seen this done. In fact, even worrying about deadlocks is not common with many programmers...

And for developers that do worry about deadlocks (ie. the good ones)... Deadlock prevention techniques generally implemented are (1) using a coarse lock, or (2) lock ordering -- building a release mechanism just seems too elaborate and may even enforce using a "framework".

Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13399

Devaka Cooray wrote:Found your other topic.


Thanks Devaka. I locked the other topic (and posted a link back to here).

Henry
Alexander Danilou
Greenhorn

Joined: May 08, 2009
Posts: 28
Thank you,

Devaka wrote:
In my view, this question cannot be accurately answered without having more details on it.

This was exactly my concern. At this point I just want to pass SCJP exam. I really hope that real exam will not contain such questions. But since this statement and answer "true" is on the K&B Mock exam, I was concerned.

This message was edited 1 time. Last update was at by Alexander Danilou

Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2586

Henry Wong wrote:In theory, this may be true. In practice, I have never seen this done.

Completely agree. I can't even imagine a dead-lock situation in practice, which should be prevented by using wait()/notify() methods.

Devaka.
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2586

Alexander Danilou wrote:This was exactly my concern. At this point I just want to pass SCJP exam. I really hope that real exam will not contain such questions. But since this statement and answer "true" is on the K&B Mock exam, I was concerned.

You may encounter with same type questions on the real exam, but with some additional details. On that case it is no doubt to choose "true" as the correct answer.

Devaka.
 
 
subject: lingering wait()/notify() and deadlock doubt
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture