Java Program on MultiThreading by implementing Runnable Example 3

PROGRAM:
class ThreadOne implements Runnable {
    Thread t;

    ThreadOne() {
        System.out.println("I'm One's Consturctor");
        t = new Thread(this);
        t.start();
    }

    public void run() {
        System.out.println("ThreadOne is running");
    }
}

class ThreadTwo implements Runnable {
    Thread t;

    ThreadTwo() {
        System.out.println("I'm Two's Consturctor");
        t = new Thread(this);
        t.start();
    }

    public void run() {
        System.out.println("ThreadTwo is running");
    }
}

class RunnableDemo {
    public static void main(String[] args) {
        ThreadOne t1 = new ThreadOne();
        ThreadTwo t2 = new ThreadTwo();
        System.out.println("I'm main");
    }
}
OUTPUT:
I'm One's Consturctor
ThreadOne is running
I'm Two's Consturctor
I'm main
ThreadTwo is running

Popular Posts