File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When does the thread run? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "When does the thread run?" Watch "When does the thread run?" New topic

When does the thread run?

josie chen

Joined: Mar 20, 2003
Posts: 6

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

Joined: Dec 20, 2001
Posts: 3271
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.

SCJP Tipline, etc.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 12, 2003
Posts: 93
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
I agree. Here's the link:
subject: When does the thread run?
It's not a secret anymore!