aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Oct 11, 2000
Posts: 63
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
 
subject: Threads
 
Similar Threads
join()
Thread question
Concurrent threads
why thread priority is not working here
Creating multiple children threads