It seems windows thread mechanism and scheduler is rather lazy or The our lab systems are too powerful (well they are , a 2GB RAM with core 2 quad Intel platforms at it's heart) so I write a simple program to check the behaviour of threads, I implemented simple code including three classes a simple class extending thread interface , a class implementing runnable interface and a main class to keep everything going
following are the code of each of the three classes.
public class MainClass {
public static void main(String args[]){
MyThread t= new MyThread();
MyRunnable mr = new MyRunnable();
Thread thread = new Thread(mr);
t.start();
thread.start();
}
}
public class MyRunnable implements Runnable{
public MyRunnable() {
}
public void run(){
for(int i=1;i<=5000;i++){
System.out.println("runnable is running");
}
}
}
class MyThread extends Thread{
public void run(){
for(int i=1;i<=5000;i++)
System.out.println("The extended thread is running");
}
}
take note of the heavy loop I created in both threads , it is not something to hog your CPU cycles(well it does so) but if I decrease the value by one zero the the ouput seems not of any thread importance , if I reduced loop to 500 , I got 500 lines of "The extended thread is running" followed by 500 lines of "runnable is running" , it seems that either the JDK implementation in windows doesnot like thread much or the underlying thread handling in windows system(if JVM maps thread handling to underlying system) is awkward, however the above code show me some real grace with first "runnable is running" after 638 lines of "The extended thread is running" , that's just an observation, everything else works fine.