File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When does the thread run?

 
josie chen
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1) Compilation and run but no output
2) Compilation and run with the output "Running"
3) Compile time error with complaint of no Thread target
4) Compile time error with complaint of no access to Thread package
The answer 2 is absolutely right.
But I think the answer 1 might be right, too.
When thread's start() method is called, in theory, it registers to thread scheduler and ready to run.If I am wrong, please correct me.

Edited by Corey McGlone: Added Code Tags
[ April 04, 2003: Message edited by: Corey McGlone ]
[ April 04, 2003: Message edited by: josie chen ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Executing this program will always result in the output "Running" being displayed. Once you've started your thread, the application can not terminate until that thread has completed. Had that thread been made a daemon thread, then either of the first 2 answers could be correct.
Corey
 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
josie, may I suggest that you give a hint of what your question is about in the Topic header.
For example, for this one, instead of "Who can answer me?", you might say "Thread question" or "When does the thread run"
 
preeti khane
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
corey,
could you elaborate / explain your statement.. I am assuming you mean to say change the thread to daemon before starting the thread.. If a thread is changed after it has started then a IllegalStateException gets thrown...
And a daemon thread in this case would not have been an actual thread, hence run would not be executed for it.. Am I right
thanks
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic