File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic