Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
Why does the program not produce any output on running?
public class Base extends Thread{
public static ThreadGroup group = new ThreadGroup("gprs");
public static void main( String []args){
Thread th1 = new Thread(group, "Thread1");
Thread th2 = new Thread(group, "Thread2");
th1.start();
th2.start();
}
public synchronized void run(){
System.out.println(" Threads ! Please Stop ");
try{
group.wait();
}
catch(InterruptedException ie){}
}
}
----Sandy
 
lakshmi nair
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because you are not calling the run method which you overrided, but the run method in class Thread. You are creating two threads (Thread class objects)and calling start. Instead, try creating your class object and call start() which will execute the run and print " Threads ! Please Stop "
lakshmi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!