Threads

Hi,

I want to understand Threads in Java programming. I have 3 classes:

public class MainClass extends Thread {

public MainClass(){

}

public static void main(String[] args) {

Thread1 thread1 = new Thread1();

Thread2 thread2 = new Thread2();

MainClass m = new MainClass();

m.start();

thread1.start();

System.out.println("thread1 start");

thread1.run();

System.out.println("thread1 run");

thread2.start();

System.out.println("thread2 start");

thread2.run();

System.out.println("thread2 run");

}

public void run(){

System.out.println("main thread");

}

}

class Thread1 extends Thread {

private Thread2 thread2;

public Thread1(){

thread2 = new Thread2();

}

public void run(){

thread2.start();

System.out.println("thread1 is current");

}

}

class Thread2 extends Thread {

public void run(){

System.out.println("thread2 is current");

}

}

Can someone tell me wat is wrong with this code?What is the different beetween run() and start()?

[1165 byte] By [Blaz1a] at [2007-11-26 17:15:24]
# 1
You'll have to debug your own program.But the difference between run and start:run() simply calls the method of that name, which does whatever you coded.start() "forks" processing - one leg executes your "run" code; the other returns to the caller.
bschauwejavaa at 2007-7-8 23:43:24 > top of Java-index,Java Essentials,Java Programming...