Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is a blocked/blocking thread

 
Tapio Niemela
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, could someone help me please. I have hard time figuring out what is "Blocked" thread and what is "blocking" thread. I understand that "Blocked" thread is a thread which doesn't get any CPU-processing time due to one of the following reasons:

a) It has called sleep method
b) It has called wait method and is waiting a notify-method to be invoked
c) It is in middle of some I/O-operation waiting it to complite

But what is "Blocking" thread then? If I have understood correctly "Blocking" thread might be a ,for example, thread which is "sleeping" (eg has called sleep) or processing I/O-operation inside synchronized method/block, so other threads can't invoke any synchronized method/block because the "Blocking" thread has a lock. Also if I've understood correctly wait doesn't apply here, because it gives processing time for other threads (eg "lends" lock to other threads). If I have misunderstood something please inform me..thanks
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A thread is either ready to execute, runnable, or not ready to execute, blocking.

Every operating system has its own terminology for these states. Java uses runnable/blocking. Another o/s calls this active/suspended. Etc.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different books have different terminology and definitions for this, so depending where you get your information from, you may read something different. However since JDK 1.5, the Thread class has had a getState() method which returns a Thread.State instance. This can be very useful for learning what's happening to a thread at any given time, and so it's convenient to use the definitions provided by Sun in the API for Thread.State. According to these, (a) is in TIMED_WAITING, and (b) is in either WAITING or TIMED_WAITING (depending on whether the wait() method had a timeout parameter). For (c), it's hard to say, because it really depends on how the particular IO method has been written. I've tested a number of examples of IO methods, and it seems that sometimes a "blocking" IO method is WAITING, or TIMED_WAITING, or BLOCKED, or RUNNABLE. There's no way to say, in general - we would need to either test a particular method ourselves, or carefully study how a particular method is implemented.

Lastly, a BLOCKED thread is one that is attemting to enter a synchronized block, or to resume running after a wait() inside a synchronized block, but it can't because it does not yet have the lock on whatever monitor object is used for synchronization.
[ April 20, 2006: Message edited by: Jim Yingst ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!