aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread question 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 "Thread question" Watch "Thread question" New topic
Author

Thread question

sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
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

Joined: Apr 09, 2006
Posts: 72
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

Joined: Jan 16, 2008
Posts: 162
Thanks Vinayagar
Hemnathbabu Kottaiveedu
Greenhorn

Joined: Mar 13, 2008
Posts: 28
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.


SCJP 5 (100%)
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

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.


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread question