Starting a thread from another thread instead of main thread

Below is an example showing how to start another Thread, from non main thread.

#1.In main method, a thread t1 is started.
#2.In run() method of thread t1, another thread t2 is started.

class thread1 implements Runnable{
public void run(){
System.out.println("inside thread 1 now printing numbers");
for(int i=0;i<10;i++){
System.out.println(i);
}

Thread t2=new Thread(new thread2());

t2.start();


}
}
class thread2 implements Runnable{

public void run(){
System.out.println("inside thread2...");
System.out.println("program which we run has shown that we can invoke or start another thread"
+" out of the main thread also");
}
}
public class threaddemo {
public static void main (String[] args) {
Thread t1= new Thread(new thread1());
System.out.println("starting thread 1");

t1.start();


}

}


Output-

starting thread 1
inside thread 1 now printing numbers
0
1
2
3
4
5
6
7
8
9
inside thread2…
program which we run has shown that we can invoke or start another thread out of the main thread also

You may like to read:
Multi threading example
purpose of PipedInputStream and PipedOutputStream
What is block level synchronization?
What is class level synchronization?