• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To start a thread we use,
Thread t = new Thread( c);
t.start();
This calls the run method of c.
What happens when we do something like:
1) t.run();
( We know that The Thread class implements a generic thread that, by default, does nothing. That is, the implementation of its run method is empty. ) In this case will this method from the Thread class be called ? )
2) t.run();
t.start();
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. t.run();
This would execute c.run(), because if you look at implementation of Thread(Runnable c), Thread.run() calls c.run(). Here the Thread is not scheduled. It is executed like anyother method.
2. t.run(); followed by t.start();
This would execute c.run() and then t.start() method registers the thread with the scheduler and will eventually executed by calling t.run().
-Shiva
[ January 12, 2003: Message edited by: Shiva Mantri ]
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basicly, if t.run(); is in Thread A, then the method run() MUST return before the next statment in Thread A is executed.
With t.start(); maybe the whole new thread will not start executing - run() method - before all of Thread A finish executing, maybe it will act like when you call t.run(), this is totally at the merci of JVM Thread scheduler.
HTH
 
reply
    Bookmark Topic Watch Topic
  • New Topic