0

This question confused me a lot since I read its official explanation about Thread.State.

Blocked

A thread in the blocked state is waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized block/method after calling Object.wait.

Waiting

A thread in the waiting state is waiting for another thread to perform a particular action. For example, a thread that has called Object.wait() on an object is waiting for another thread to call Object.notify() or Object.notifyAll() on that object. A thread that has called Thread.join() is waiting for a specified thread to terminate.

Also I read some wonderful answers like Difference between WAIT and BLOCKED thread states in StackOverflow, but still I am not quite sure about Waiting and Blocking.

Is it right to think about these two states as follows?

  • Waiting: threads positively execute wait() or sleep() to give up the CPU cycles;
  • Blocking: threads trying to move on but the essential resources like synchronized block are taken up by others, so they have to negatively be waited;
Hearen
  • 7,420
  • 4
  • 53
  • 63

1 Answers1

-1

When a thread is in waiting state it releases the lock of the object it holds and will remain in WAITING state until any other thread calls either notify() or notifyAll() on the same object. Where a BLOCKED thread is waiting for other thread to release the lock it wants.

Sundeep
  • 452
  • 2
  • 12
  • **Didn't** you take a **quick** look at my question? – Hearen Jun 14 '18 at 09:41
  • Yes we can think in that way. A waiting and Block thread is somewhat similar the major difference is where a waiting thread is release the object lock it hold and wait till some other thread calls notify() on same object And blocked thread waits for other thread to release its lock. – Sundeep Jun 14 '18 at 10:11