• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Thread doubt about wait() method

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic