1class RunnableObject implements Runnable {
2 private Thread t;
3 private String threadName;
4
5 RunnableObject( String name) {
6 System.out.println("Creating " + threadName );
7 threadName = name;
8 t = new Thread (this, threadName);
9 }
10
11 public void run() {
12 System.out.println("Running " + threadName );
13 }
14
15 public void start () {
16 System.out.println("Starting " + threadName );
17 t.start ();
18 }
19}
20
21public class TestThread {
22
23 public static void main(String args[]) {
24 RunnableObject R1 = new RunnableObject( "Thread-1");
25 R1.start();
26 }
27}
1package com.tutorialspoint;
2
3import java.lang.*;
4
5public class ThreadDemo implements Runnable {
6
7 Thread t;
8 ThreadDemo() {
9
10 // thread created
11 t = new Thread(this, "Admin Thread");
12
13 // prints thread created
14 System.out.println("thread = " + t);
15
16 // this will call run() function
17 System.out.println("Calling run() function... ");
18 t.start();
19 }
20
21 public void run() {
22 System.out.println("Inside run()function");
23 }
24
25 public static void main(String args[]) {
26 new ThreadDemo();
27 }
28}