Saturday, 10 June 2017

Java Tutorial Java Thread (Reentrant monitor | Reentrant lock in java) ~ foundjava


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)
DisplayMessage.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.java
public class ReentrantExample
{
    public static void main(String args[])
    {
        Thread t1 = new Thread()
        {
            public void run()
            {
                new DisplayMessage().displayName();
            }
        };
        t1.start();
    }
}
Output
Hello Peter

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment