Monday, September 18, 2017

Monitors

AIM: the main aim this program is to use a Synchronized method to lock an object by using monitors 
Source Code:

public class MonitorsExample{
public synchronized void m() { 
    n(); 
    System.out.println("this is m() method"); 
    } 
    public synchronized void n() { 
    System.out.println("this is n() method"); 
    }
public static void main(String args[]){ 
final MonitorsExample re=new MonitorsExample(); 
Thread t1=new Thread(){ 
public void run(){ 
re.m();//calling method of Reentrant class 
}; 
t1.start(); 

}} 


 Input & Output