ThreadDemo.java Source code

Java tutorial

Introduction

Here is the source code for ThreadDemo.java

Source

class ThreadDemo implements Runnable {

    public void run() {
        for (int i = 1; i < 13; i++) {

            System.out.println(Thread.currentThread().getName() + "  " + i);
            try {
                // thread to sleep for 1000 milliseconds plus 500 nanoseconds
                Thread.sleep(1000, 500);
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }
}

public class Main {

    public static void main(String[] args) throws Exception {
        Thread t = new Thread(new ThreadDemo());
        t.start();

    }
}