I want to print 1 by Thread-1,
 2 by Thread-2,
 3 by Thread-3
like 123123123 and so on

this i want to achieve using only one runnable object shared by multiple threads 
baiscally the way i have tried is 
have used one atomicInteger as signalling to indicate which should print
and used wait and notify to transfer the control between the threads and have
used threadName check to allow the specific thread to print

I have tried this like below and its not working can someone please help me in this.

```
/** Main class which creates 3 threads using one runnable and 
    starts the 3 threads */ 
package PrintOneTwoThree;
public class MainClass
{
  public static void main(String args[])
  {
    //one runnable is created and shared by 3 threads
    final PrintNumbersConsecutively printRunnable = new 
                               PrintNumbersConsecutively();
    Thread t1 = new Thread(printRunnable, "Thread1");
    Thread t2 = new Thread(printRunnable,"Thread2");
    Thread t3 = new Thread(printRunnable,"Thread3");

    t1.start();
    t2.start();
    t3.start();
 }
}

/** Each of the three threads are made to print 1 ,2 and 3 */
package PrintOneTwoThree;
import java.util.concurrent.atomic.AtomicInteger;
public class PrintNumbersConsecutively implements Runnable
{
  private Object monitor = new Object();
  AtomicInteger atomicInt = new AtomicInteger(1);

@Override
public void run()
{
    System.out.println(Thread.currentThread().getName()+"Started");
    // TODO Auto-generated method stub
    printNumbers();
}

// method to print the numbers using 3 different threads 1 ,2 and 3
public void printNumbers()
{
    try
    {
        while(true)
        {
            synchronized (monitor) 
            {
                System.out.println(Thread.currentThread().getName()+"held 
                               the lock of monitor");
                System.out.println("printVal is"+ atomicInt);

                 //Thread1 should print 1
                if(atomicInt.get() == 1 && 
                        Thread.currentThread().getName().equals("Thread1"))
                {
                    //prints 1 and next awakes second thread by setting
                    // atomic int to 2
                    System.out.println(1);
                    atomicInt.set(2);
                    monitor.notifyAll();

              System.out.println(Thread.currentThread().getName()+"Releasing 
              the lock of monitor");
                    monitor.wait();
                }

                //Thread 2 should print 2
                if(atomicInt.get() == 2 && 
                     Thread.currentThread().getName().equals("Thread2"))
                {
                    //prints 2 and next awakes third thread by setting
                    // atomic int to 3
                    System.out.println(2);
                    atomicInt.set(3);
                    monitor.notifyAll();
                    monitor.wait();
                }

                //Thread 3 should print 3
                if(atomicInt.get() == 3 && 
                   Thread.currentThread().getName().equals("Thread3"))
                {
                    //prints 3 and next awakes first thread by setting
                    // atomic int to 1
                    System.out.println(3);
                    atomicInt.set(1);
                    monitor.notifyAll();
                    monitor.wait();
                }
            }
        }

    }
    catch(InterruptedException e)
    {
        //catches the interrupted excpeiton
    }
}
}

```

output is 

```

printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor
printVal is1
Thread2held the lock of monitor

```