Aula03ThreadII

class RunnableThreadDemo implements java.lang.Runnable {
    // RUN METHOD IS EXECUTED WHEN THREAD FIRST STARTED
    public void run() {
        System.out.println("I am an instance of the java.lang.Runnable  interface ");
    }

}

public class aula03ThreadII {
    public static void main(String[] args) {
        System.out.println("Creating runnable object");

        // CREATE RUNNABLE OBJECT
        Runnable run = new RunnableThreadDemo();

        // CREATE A THREAD, AND PASS THE RUNNABLE OBJECT
        System.out.println("Creating first thread");
        Thread t1 = new Thread(run, "Thread 1");

        // CREATE A SECOND THREAD, AND PASS THE RUNNABLE OBJECT
        System.out.println("Creating second thread");
        Thread t2 = new Thread(run, "Thread 2");

        // START BOTH THREADS
        System.out.println("Starting both threads");
        t1.start();
        t2.start();
    }
}
Tags : ,

0 thoughts on “Aula03ThreadII”

Leave a Reply

Your email address will not be published.

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