• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Thread question!  RSS feed

 
Nitin Bhagwat
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to understand Threads. Wrote one program. It is compiling without any errors but do not show text "THREAD RUNNING". Please help!!

class th
{
public static void main(String ara[])
{
new inp();
}
}

class inp implements Runnable
{
Thread th;

inp()
{
th = new Thread();
th.start();
}


public void run()
{
System.out.println("THREAD RUNNING");
}

}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin,
Welcome to Javaranch!


should be


"this" refers to the inp instance that you are calling the constructor from. The Thread constructor needs to know which thread you want to run. Otherwise it will just run the thread class' run method (which does nothing.)
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Threads and Synchronization forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!