jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green: incorrect option? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green: incorrect option?" Watch "Marcus Green: incorrect option?" New topic
Author

Marcus Green: incorrect option?

Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504

Question 44)
Given a reference called
t
to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.
1) t.yield();
2) Thread.yield();
3) yield(100); //Or some other suitable amount in milliseconds
4) yield(t);

Answer to Question 44)
Objective 7.1)
yield is a static method and causes whatever thread is currently executing to yield its cycles.
1) t.yield();
2) Thread.yield()
(Thanks Roseanne )


Such a behavior is quite possible, but not guaranteed as the same thread may be chosen to run by the scheduler after yielding. Therefore, I think having this question asking which of the following can cause it to give up cycles to allow another thread to execute is more appropriate.
Marcus Green's exam 3, Question 44
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
I agree. In fact, the thread may not even yield at all.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
In my opinion, it is possible that on some virtual machines neither "must" or "can" is appropriate.
"On JVM implementations that employ pre-emptive scheduling policies, especially those on multiprocessors, it is possible and even desirable that the scheduler will simply ignore this hint provided by yield." Concurrent Programming in Java, Lea 1.1.2.5
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I think that can is OK; it's vague enough either way. Maybe it will never happen on a particular JVM; maybe it will always happen on another JVM; either way, "can" is appropriate, IMO.
There's another problem with this questin which I consider more serious:
Given a reference called t to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to execute.

What's "it"? The thread represented by t seems most likely though that's not definite. The problem is, ifyou call t.yeild(), that isn't likely to have any effct on t at all - unless t just happens to also be the currently executing thread. I think that this is the sort of thing that the real exam might actually test you on - whether or not you know that yield() is static and therefore most likely has no effect on t. And the question is extremely ambiguous in this regard. The answer is less ambiguous, except that it does say that option 1 is correct - and in many cases, it's not. I suppose that if we add the word "can" as previously suggested, that might be vague enough to allow option 1 to be correct. But that's still misleading. The most likely scenario is that option 1 will have no effect at all on t.


"I'm not back." - Bill Harding, Twister
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Good point, Jim. I ran across a question on a mock exam just today where the trick was about thread t1 invoking t2.sleep().
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
How about:
Given a reference called t to a class which extends Thread, which of the following may cause the currently executing thread to give up cycles to allow another thread to execute?
[ October 13, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thomas, I think your statement gives a strong hint as to the answer, namely that t and the currently executing thread are two different ideas.
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
I think it should be changed to can, who is this Marcus Green person?


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I think it should be changed to can,
No comment on the other point?
While I might agree with Marlene that Tom's suggested wording make the problem too easy, that's preferable to being wrong of misleading.
Another possible wording is
"which of the following can cause a thread to give up cycles..."
or (going back to the other part)
"which of the following will typically cause a thread to give up cycles..."
who is this Marcus Green person?
I think he's a myth. Who was that masked man?
[ October 13, 2003: Message edited by: Jim Yingst ]
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
who is this Marcus Green person?
he is a legend


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Green: incorrect option?
 
Similar Threads
Ambiguous Thread Question?
Marcus Green #3 Question 44
Please, help! I'm a bit confused :)
Marcus
Marcus Green #3, Q44