Click here to watch in Youtube :
https://www.youtube.com/watch?v=Z6yStBsCzvw&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
![]() |
Java Tutorial Java Thread (Reentrant monitor | Reentrant lock in java) |
class DisplayMessage
{
/*
* Declaring two synchronized method displayName() and
* displayHello().one synchronized method calling to
* another one.
*/
public synchronized void displayName()
{
displayHello();
System.out.println("Peter");
}
public synchronized void displayHello()
{
System.out.print("Hello ");
}
}
ReentrantExample.javapublic class ReentrantExample
{
public static void main(String args[])
{
Thread t1 = new Thread()
{
public void run()
{
new DisplayMessage().displayName();
}
};
t1.start();
}
}
OutputHello Peter
Click the below link to download the code:
No comments:
Post a Comment