aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Execution flow in threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Execution flow in threads" Watch "Execution flow in threads" New topic
Author

Execution flow in threads

Rajat Asani
Greenhorn

Joined: Mar 26, 2008
Posts: 27


My questions is the how come i got this sequence as output in my program??

I am aware that the output of threads cannot be determined because of thread scheduler. Also I know that the Main and the "Rajat" thread will run independently. But in this case the execution flow in the run methods would be sequential. ie. the exception would always be thrown after the println statement printing "start". Then how come i see "start" printed after the exception.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

But in this case the execution flow in the run methods would be sequential. ie. the exception would always be thrown after the println statement printing "start". Then how come i see "start" printed after the exception.


This is *not* a threads issue. Basically, "start" is a message that goes to standard out. And the runtime exception generates a message that goes to standard err. So, the order that they are printed will depend on the order the streams are flushed.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rajat Asani
Greenhorn

Joined: Mar 26, 2008
Posts: 27
Got it....Thanks.

But does this mean that this can happen in execution of normal programs where no threads are involved?
If so then do we need to be on a lookout for this time lag in streams being flushed to different methods when determining the output of questions in the exam?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

If so then do we need to be on a lookout for this time lag in streams being flushed to different methods when determining the output of questions in the exam?


How many of these types of mock questions, where they test the ordering of stdout and stderr, have you seen so far?

Henry
Rajat Asani
Greenhorn

Joined: Mar 26, 2008
Posts: 27
Not even one. Thats why this concept of time lag in flushing was a surprise for me. So i thought i should confirm. Please don't get me wrong, am just preparing for the worse.
 
Don't get me started about those stupid light bulbs.
 
subject: Execution flow in threads