• 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

Thread doubt about wait() method

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread1 and Thread2 are trying to get an Object lock,only one thread can get the lock ..take as Thread1 ,then Thread2 will be Non-Runnable

If Thread1 calls wait,then it goes to blocked State or non-runnable state and thread2 gets the lock and enters the Synchronized code.


After this,if Thread2 issues wait,it goes to blocked state. Now what about Thread2,will it gets the lock and moves to Running state? (as there are only 2 threads)
 
Ranch Hand
Posts: 62
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have to call notify() or notifyAll() at some point. Maybe before putting Thread2 to sleep.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends how badly you write your code!! If you write something like the following



The you get a deadlock; something you always have to be aware of when writing multithreaded code.

Regards

Dave
 
reply
    Bookmark Topic Watch Topic
  • New Topic