This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Threads
 
Similar Threads
Thread question
join()
Creating multiple children threads
why thread priority is not working here
Concurrent threads