Monday, September 27, 2010

Take a trip into Java Monitor with your source code






                      line 1:  synchronized(obj){//Entry Set
                      line 2:       System.out.println ("I am the master of monitor");//Owner
                      line 3:       obj.wait();//Wait Set
                                 }
                      line 4:           //Out of the monitor

More than one thread can be blocked/found on line 1 , line 3 and line 4 at the same time, but there can only be one active thread at the same time at line 2 as a monitor owner.

You may want to check this sample also : http://javabender.blogspot.com/2010/09/example-for-understanding-javas-wait.html

No comments:

Post a Comment