title: Creating thread using Runnable object
body: <p>I am trying to create a thread from an object of a class implementing Runnable from java.lang.Runnable
  but its not working.</p>
  
  <pre><code>piyush@piyush-Inspiron-5559:~/Desktop/java_prog$ javac Runnable.java
  Runnable.java:27: error: no suitable constructor found for Thread(counter,String)
      Thread td=new Thread(obj,"bac");
                ^
  constructor Thread.Thread(Runnable,AccessControlContext) is not applicable
    (argument mismatch; counter cannot be converted to Runnable)
  constructor Thread.Thread(ThreadGroup,Runnable) is not applicable
    (argument mismatch; counter cannot be converted to ThreadGroup)
  constructor Thread.Thread(ThreadGroup,String) is not applicable
    (argument mismatch; counter cannot be converted to ThreadGroup)
  constructor Thread.Thread(Runnable,String) is not applicable
    (argument mismatch; counter cannot be converted to Runnable)
  Note: Some messages have been simplified; recompile with - Xdiags:verbose to get full output
  1 error
  </code></pre>
  
  <p>this is the error.
    the code is as follows.........</p>
  
  <pre><code>import java.io.*;
  interface Runnable{
  public void run(); 
  }
  class counter implements Runnable {
  Thread t=Thread.currentThread();
  private int x;
  public counter(){x=0;}
  public int getval(){return x;}
  public void run()
  {
      try{
      while(x&lt;5){
          System.out.println(t.getName()+ ":" + (x++));
          Thread.sleep(250);
      }
      System.out.println("Exit from thread:"+t);}
      catch(InterruptedException e){
          System.out.println("InterruptedException");
      }
  } 
  }
  class client {
  public static void main(String args[])
  {
      counter obj=new counter();
      Thread td=new Thread(obj,"bac");
      td.start();
      int val;
      try{
      do{
          val=obj.getval();
          System.out.println(td.getName()+ ":" + val);
          val=6;
          Thread.sleep(1000);
      }while(val&lt;5);
    }
      catch(InterruptedException e)
      {
          System.out.println("InterruptedException 2");
      }
      System.out.println("Exit from thread:"+td.getName());
      }
  }  
  </code></pre>
  
  <p>Do i have to create any thread constructor.?
  or i m am to access the Runnable class from java.lang library??
  what's the issue here??</p>