Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Behavior of run and Start methods. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads Behavior of run and Start methods." Watch "Threads Behavior of run and Start methods." New topic

Threads Behavior of run and Start methods.

nitin goswami

Joined: Mar 01, 2005
Posts: 25
Q.What would be the output???
class MyThread extends Thread {

public void run() {
System.out.println("Active Threads"+Thread.activeCount());

public void start(){

public class MyRunnable implements Runnable {
public void run() {
System.out.println("Active Threads "+Thread.activeCount());

public void start(){
public static void main(String args[]){
//Creating two thread Objects
MyThread myThread= new MyThread();
MyRunnable myRunnable= new MyRunnable();

//Starting Two thread of Execution.
myThread.start(); //***Line #
new Thread(myRunnable).start();


Now comes my Questions 1)Why not Executed the run of MyThread class?
2)Active Thread Count 3?if we do not start myThread(if we comment /*** Line #),just create an object of MyThread class ,it gets Counted as a Active Thread.
Pl explain.thx
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
For the first question, you have overridden the Thread start method in your MyThread class so it no longer calls the run method.
I agree. Here's the link:
subject: Threads Behavior of run and Start methods.
It's not a secret anymore!