ThreadX.java Source code

Java tutorial

Introduction

Here is the source code for ThreadX.java

Source

/*
 * Output:
Hello
Hello
Hello
 */

class ThreadX extends Thread {

    public void run() {
        try {
            while (true) {
                Thread.sleep(2000);
                System.out.println("Hello");
            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}

public class MainClass {

    public static void main(String args[]) {

        ThreadX tx = new ThreadX();
        tx.start();
    }
}