//================================================================================
// Terminating main, while the "user" thread continues executing
// Enter 'stop' and press enter
//================================================================================
import java.util.Scanner;

public class TerminateMain1
{
    public static void main(String[] args)
    {
        TerminateMain1User o = new TerminateMain1User();        //create a program object

        Thread t1 = new Thread(o);                              //create a thread 
                                
        System.out.println("main - Enter 'stop' to terminate main");
        System.out.println("       user thread should continue executing \n");

        t1.start();                                     //make the thread eligible to run

        Scanner sc = new Scanner(System.in);

        String s = "";
        while (! s.equals("stop"))
            s = sc.next();                              //get next token
                
        System.out.println("main terminated.\n");
        return;
    }
}

class TerminateMain1User  implements Runnable
{
    public void run( )                                  //must override method
    {
        for (int i = 1; i <= 20; i++)
        {
            System.out.println("thread 1 - count: " +  i);

            try
            {
                Thread.sleep(1000);                     //delay by 1 seconds
            }
            catch(InterruptedException e)               //catch interruption
            {
            }                                           //do nothing
        }
    }
}