• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wait() n notify() method problem

 
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

output: waiting for b to finish
total is: 4950

my question:
1:
when wait() is executed,the thread must give up its lock and wait to reacquire it and then proceed with the code following it. But here "zzz" is not printing thus indicating that its exiting the loop. Can someone explain?
2:
If i use sleep() in the run(),then the output is zero.
But when a thread goes to sleep it do not release its lock, so how can the code succeeding the "wait()" can proceed?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit please Quote Your Sources when you post a mock exam question. Also Use Real Words instead of words like "n" "q" "dnt"...
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Amit please Quote Your Sources when you post a mock exam question. Also Use Real Words instead of words like "n" "q" "dnt"...


I found this question in K&B book and I modified it to understand it deeper. As with using "n" and "q", sorry about that.. guess in-spite of my sincere effort to prevent the chat writing style,it crept in while writing
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Amit the b.wait() call in main method is throwing an exception as main thread doesn't have the lock on b object as its not in a synchronized block. Also wait-notify is not on the SCJP objectives now...
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Amit the b.wait() call in main method is throwing an exception as main thread doesn't have the lock on b object as its not in a synchronized block. Also wait-notify is not on the SCJP objectives now...



Yes you are right,its throwing IllegalMonitorStateException.
I saw right now that the wait-notify is not in the exam but its in the k&b book that I purchased 2months ago only

Thanks for your help.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The K&B book was released just before the exam got an update. Serialization is also no longer on the exam.
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wouter Oet wrote:The K&B book was released just before the exam got an update. Serialization is also no longer on the exam.


yes i realized about the serialization also after finishing the topic what a waste of time :/ Now am gonna do a check for the topics excluded so that I dont end up wasting time anymore.
Thanks for replying
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic