what will be the result of the above program.....wat is the order of the sysout. can you please explain them....after a start() command will the thread execute the sysout below it or will dit skip that and invoke the run method...wat is the order of execution....please explain....thanks in advance!!!
Joined: Feb 13, 2004
Ok Shilpa, I'd just added few more messages in your code, can you run it and see how it works?
Joined: Jul 26, 2006
vijay the problem is im in office now n cant run it now.....im having my exam day after....so if you can give the output n explain it in words ...it wuld be really really helpfull
After t.start() is called, r's run method can be executed at the platform's discretion. It's unlikely that run will be invoked immediately after the start call (prior to the next line in the current thread), but it's possible.
No lines are "skipped." After 'r' is given a chance to run, the main thread will resume where it left off.
IMPORTANT EXAM TIP: Note that sleep is a static method in Thread. It puts the current thread to sleep, even if called through some other Thread instance. For example, in this code, when you call t.sleep, you are not putting t to sleep -- you are just calling Thread.sleep by way of t.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org