• 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

Thread...

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

public class SimpleThread extends Thread {
public void run ( ){
System.out.println ( "Executing simple Thread");
}
public void myThread() {
System.out.println ( "Executing myTthread() method");
}
public static void main ( String args [ ]) {
SimpleThread st = new SimpleThread ( );
st.start( );
st.myThread();
}
}
output of this program is::: Executing my thread()
Executing simple thread()
but i expected the output to be:: Executing simple thread()
Executing mythread()
anybody can tell me what im missing..
thanks..
regards.
Jaya Murugan
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anybody can tell me what im missing..
Actually nothing is missing and both the answers are correct.
starting a thread by st.start() does NOT guarantee that run() method will be invoked immediately.. It is up to the operating system when to make a thread running.. the start method only brings thread st into RUNNABLE state. but OS only decides when it runs mean while other methods can start executing.. like
myThread above..
HTH
Sasidhar

[This message has been edited by sasi dhulipala (edited January 09, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic