• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execution flow in threads

 
Rajat Asani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajat Asani
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic