• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads !

 
Vikram Deshmukh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
here i give u a code, If i can execute a run method, by simply invoking
threadObject.run(); then what is the need of or keeping threads in runnable pool ?
So how come we can avoid OS Scheduler ? So programmers will have their own set of controlled threads by simply invoking run method.
So is there any diffce between invoking start() & run() method or other way why to keep threads at the hand of OS scheduler, when we can decide, which thread to run ?
waiting for ur reply,
from,
Vikram.
/////////// code here
public class myThread extends Thread
{
public static void main(String args[])
{
myThread my1 = new myThread();
myThread my2 = new myThread();
my2.run();
my1.start();
}
public void run()
{
System.out.println("invoked the thread");
}
}
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vikram
If you invoke the run method directly, it will not start a new thread. It will just be a synchronous method call.
On the other hand, if you invoke the start method, it gets added to the thread pool, gets picked up by the scheduler and eventually runs as an independent task.

Ajith
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This mas Ajith has said it all.....
 
paul wheaton
Trailboss
Posts: 22063
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the threads forum ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!