Java Data Type Tutorial - Java Thread.run()








Syntax

Thread.run() has the following syntax.

public void run()

Example

In the following code shows how to use Thread.run() method.

//from   w  ww .jav  a  2 s. c om
public class Main {
  public static void main(String args[]) {

    Thread t = new Thread(new ThreadDemo());

    System.out.println("thread  = " + t);
    t.start();
  }
}

class ThreadDemo implements Runnable {
  public void run() {
    System.out.println("Inside run()function");
  }
}

The code above generates the following result.