• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

lingering wait()/notify() and deadlock doubt

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 6832
1299
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Devaka Cooray
Sheriff
Posts: 6832
1299
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 6832
1299
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic