Thread: some queries
View Single Post
  #8 (permalink)  
Old 11-24-2007, 09:10 PM
staykovmarin staykovmarin is offline
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Is ConsoleProgram a subclass of Thread, or is it implementing Runnable? If it was, then what you are doing when you create a run() method, is you are telling it what the thread will execute (by overriding the run() method)

If ConsoleProgram extends Thread:
Code:
AverageTwoDoubles avg = new AverageTwoDoubles(); avg.start()
That will run the code inside the run() method.


If ConsoleProgram implements Runnable
Code:
Thread t = new Thread(new AverageTwoDoubles()); t.start();
That will run the code in the run() method (again in a separate thread)

edit: if ConsoleProgram doesn't extend Thread, nor implement Runnable, then you are simply creating a method called run() that executes some code.

Last edited by staykovmarin : 11-24-2007 at 09:14 PM.
Reply With Quote