Ask Google

Custom Search

Sunday, February 20, 2011

Ask Java 4

Today i will cover one more question here..simple yet basic

What is mutual exclusion? How can you take care of mutual exclusion using Java threads?



Java provides many utilities to deal with mutual exclusion with the use of threaded programming.
Mutual exclusion is where no two processes can access critical regions of memory at the same time.

For mutual exclusion, you can simply use the synchronized keyword and explicitly or implicitly provide an Object, any Object, to synchronize on.

The runtime system/Java compiler takes care of the gruesome details for you. The synchronized keyword can be applied to a class, to a method, or to a block of code. There are several methods in Java used for communicating mutually exclusive threads such as wait( ), notify( ), or notifyAll( ). For example, the notifyAll( ) method wakes up all threads that are in the wait list of an object.


Blogging

No comments:

Post a Comment

5L15K

  © Blogger template The Beach by Ourblogtemplates.com 2009

Back to TOP