//===============================================================
// Forcing a thread to sleep 
//===============================================================
public class Sleep
{
    public static void main(String[] args)
    {
        SleepOdd  odd  = new SleepOdd( );       //create a program object
        SleepEven even = new SleepEven( );

        Thread t1 = new Thread(odd);            //instantiate a thread 
        Thread t2 = new Thread(even);             

        t1.start();                             //make it eligible for the scheduler to run it
        t2.start();                         
    }
}

class SleepOdd implements Runnable
{
    public void run( )
    {
        for (int odd = 1; odd <= 20; odd += 2)
        {
            System.out.println("1st thread - count: " +  odd);

            try                                 //must be in a catch block 
            {
                Thread.sleep(500);              //sleep for 1/2 second
            }
            catch (InterruptedException e)      //must catch this exception
            { }
        }                                 
    }
}

class SleepEven implements Runnable
{
    public void run( )
    {
        for (int even = 2; even <= 20; even += 2)
        {
            System.out.println("\t\t\t" +  "2nd thread - count: " +  even);

            try                                 //must be in a catch block 
            {
                Thread.sleep(200);              //sleep for 1/5 second
            }
            catch (InterruptedException e)      //must catch this exception
            { }
        }
    }
}