Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread question

 
sridhar row
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source: http://www.sun.com/training/certification/assessment/055.jsp



Which two can result? (Choose two.)

a)in pre
b)pre in
c)in post pre
d)in pre post
e)pre in post
f)pre post in

The only answer i get when i compile and run this program several times is option e. And my other guess is option f. Can someone tell what the answer is with some explanation please. Thanks!
[ May 05, 2008: Message edited by: sridhar row ]
 
Vinayagar Karpagam
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hope the answer could be d & e.

In case the Order thread gets completed before main executes "pre", the output will be "in pre post".

In case the Order thread gets executed after main executes "pre", the output will be "pre in post".

"post" will always occur in the output and will be after "pre".

Regards,
Vinayagar. K
 
sridhar row
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vinayagar
 
Hemnathbabu Kottaiveedu
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vinayagar,

I think the only correct option is e(pre, in & post) because even if the child thread starts executing its run method before the main thread prints "pre" the child thread is in sleep mode for 2 secs and during this time the main thread will execute its code because there is no other live thread. After that the main thread is blocked for the child thread to complete and hence "in" will be printed.
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi HemanthBabu,

Although the answer will be e most of the times or you can say that 99.9999% of the time, but still it quite ambiguous that during that 2 second main thread will execute or not, we don't know how the JVM and OS treats thread ! so we can not say with 100% surety that answer will be e every time and again the proof of reverse can not be given, this is entirely theory.

so i think answer should be d and e.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic