ThreadDemo.java Source code

Java tutorial

Introduction

Here is the source code for ThreadDemo.java

Source

class ThreadDemo implements Runnable {
    public void run() {
        // returns the identifier of this Thread.
        System.out.println("Name = " + Thread.currentThread().getName());
        System.out.print("Id = " + Thread.currentThread().getId());
    }
}

public class Main {

    public static void main(String args[]) {

        // thread created
        Thread t = new Thread("java2s.com thread");
        // set thread priority
        t.setPriority(1);
        // prints thread created
        System.out.println("thread  = " + t);
        // this will call run() function
        t.start();
    }

}