jQuery in Action, 2nd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Mock exam2 - thread scheduling. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Marcus Mock exam2 - thread scheduling." Watch "Marcus Mock exam2 - thread scheduling." New topic
Author

Marcus Mock exam2 - thread scheduling.

Anju Rao
Ranch Hand

Joined: Feb 23, 2000
Posts: 43
Hi ALL,
Following is the question:
What can cause a thread to stop executing?
1) Program exits via a call to System.exit(0)
2) Another thread is given a higher priority
3) call to thread's stop method
4) call to halt method of thread.
Answers: 1,2
I think it is only 1. Because scheduling is platform dependent, it might not always go by priorities - could be timeslicing also? Any comments?
The same goes with the question below:
What conditions might u use yield method thread class?
1) To call from current running thread to allow another thread of same priority to run.
2) to call on a waiting thread to allow it to run
3) To call on a waiting thread of higher priority to run.
Answer: 1
As i see it, if it is timeslicing, there is no difference between 1 &3. Can somebody help me see what i am missing here?
Thanks,
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Usually it's best to have just one question per post, but these are at least close in intent.
First question:
The question asks what can cause a thread to stop, not what is guaranteed to make it stop. Thus 1 and 2 are correct, as is 3 really. stop() is deprecated, but it can still make a thread stop. A real exam qustion shouldn't ask about deprecated methods anyway, I think.
Second question:
1, 2, and 3 are all correct. You can never guarantee which particular thread will run, but calling yield() is a good step to help another thread get the chance.

"I'm not back." - Bill Harding, Twister
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
question 2 specifically states in option 1: "to call from current thread to let other threads run", whereas the other options state :" to call on another thread to run " implying the invalid form of otherThread.yield() which is incorrect since yield() can only be called from the current thread. Hence, the answer is (1).


May the Moose be with you.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Eh? All methods can only be called from the current thread, because if a thread isn't current, it isn't executing. It may be waiting to execute, but by the time it actually does execute, it has become the current thread. Any time a given bit of code is executing, anywhere, it must be in the current thread. So actually saying "call from the current thread" adds no information - "from the current thread" is implied any time you talk about calling any method. So there is no important difference between answer 1 and the other options.
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
jim, the wording of the question seems to test if one knows that one can;t make a second thread yield by calling secondThread.yield() from the first thread. just look over the wording of the answers again. hence, the answer is 1.
Rolf Weasel
Ranch Hand

Joined: Feb 26, 2000
Posts: 82
oops, my wording is a little mixed up. what i mean is, he's testing if one knows one can;t yield to a second thread by calling secondThread.yield() from the first thread.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Ah! I see - I focused on the wording of the first option, and missed what you were saying about 2) and 3). You're right. Well, actually otherThread.yield() is legal (becauce a static method can always be invoked from an instance of the appropriate class), but it doesn't actually affect otherThread directly - it affects the current thread. So the wording of 2) and 3) do indicate a misunderstanding of how yield() works. I'll read more carefully next time.
Anju Rao
Ranch Hand

Joined: Feb 23, 2000
Posts: 43
Jim, Rolf - Thanks for your replies.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Marcus Mock exam2 - thread scheduling.
 
Similar Threads
Marcus Green mock exam - 2 #24
Issue with Thread question in Marcus Green
Question on threads
Yield()
Q #24, Marcus Green ..... yield() method of threads