• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

code for thread exceution?  RSS feed

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line of code would begin execution of a thread named myThread?
this is a fill in the blank type question.
ans?
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myThread.start(); //if myThread extends Thread
myThread.run(); //if myThread implements Runnable interface

Originally posted by rahul kumar:
What line of code would begin execution of a thread named myThread?
this is a fill in the blank type question.
ans?


 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roopa,
myThread.run() does not start a Thread it just invokes the run method and that's it. To schedule a Thread for execution you have to invoke start() !!
when your class implements Runnable you have to construct a Thread with the following statement
Runnable myThread = new MyThread(); //implements Runnable
Thread t = new Thread(myThread);
t.start();
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited October 03, 2001).]
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from source
public void start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
The result is that two threads are running concurrently: the current thread (which returns from the call to the start method)
and the other thread (which executes its run method).
Throws:
IllegalThreadStateException - if the thread was already started.
See Also:
run(), stop()
 
I think I'll just lie down here for a second. And ponder this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!