//===============================================================
// Using threads by implementing the Runnable interface
// Create 2 threads that output odd/even numbers.
//===============================================================
public class Count2
{
    public static void main(String[] args)
    {
        Count2Odd odd   = new Count2Odd( );     //create a program object
        Count2Even even = new Count2Even( );

        Thread t1   = new Thread(odd);          //create a thread  
        Thread t2   = new Thread(even);         //and pass it the program object 

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

class Count2Odd  implements Runnable
{
    public void run( )                             //must override method
    {
        Thread t = Thread.currentThread( );        //get a reference to this thread

        for (int odd = 1; odd <= 100; odd += 2)
        {
            System.out.println( t.getName( ) + " - count: " +  odd);

            Thread.yield( );            //if yield, threads will alternate execution
        }
    }
}

class Count2Even  implements Runnable
{
    public void run( )
    {
        Thread t = Thread.currentThread( );

        for (int even = 2; even <= 100; even += 2)
        {
            System.out.println("\t\t\t" + t.getName( ) + " - count: " +  even);

            Thread.yield( );
        }
    }
}