aula04ThreadsComunicacao


public class aula04ThreadsComunicacao extends Thread{
    public static void main(String args[]) throws Exception
    {
// START THE ADDITIONAL NEW THREAD THE MAIN THREAD WILL BE AINTING FOR.
        Thread notificationThread = new aula04ThreadsComunicacao();
        notificationThread.start();

// WAIT FOR THE NOTIFICATION THREAD TO TRIGGER EVENT
        synchronized (notificationThread){
            notificationThread.wait();
        }

// NOTIFY USER THAT THE WAIT() METHOD HAS RETURNED
        System.out.println ("The wait is over");
    }
    public void run()
    {

//THIS IS THE ADDITONAL THREAD WHICH WAS CREATED+STARTED BY THE MAIN THREAD
        System.out.println ("Hit enter to stop waiting thread");
        try {
            System.in.read();
        }catch (java.io.IOException e){}

// NOTIFY ANY THREADS WAITING ON THIS THREAD
        synchronized (this){
            this.notifyAll();
        }
    }
}
Tags : ,

0 thoughts on “aula04ThreadsComunicacao”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.