This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads doubt?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads doubt??" Watch "Threads doubt??" New topic

Threads doubt??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

Hi Guys,

The following question is fromMarcus Green,

What can cause a Thread to stop executing?

1Calling the yield method of the instance
2Calling the yield method of another thread
3 A call to the halt method of the Thread class
4 Another thread is given higher priority

The answer was given as 4. But I guess that it should be 1?? Any thoughts on that?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
S Thiyanesh
Ranch Hand

Joined: Mar 19, 2006
Posts: 142
Both 1 and 4 can stop the thread from executing.
As yield() is a static method, it just considers the current thread.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

So, I'm right that option 1 is also correct??
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

we can argue about answer one:
Thread t = new Thread();
What can cause a Thread to stop executing?

1 Calling the yield method of the instance

You can say: "1 is true"
Because you can call a static method through an instance. And the current thread may stop executing, when it hops over this lines.
So it causes A thread to stop. The current thread is a Thread.

Or you can say: "1 is false"
Because you cannot specify the thread that should yield because yield is a static method.

I would take the second, because the next given possible answer demonstrates, that Marcus Green was simply testing that we know, the yield method is static.
But when you decide A is true, B must be true as well, because just some (specifically the current) thread may stop, when you call yield on any instance of Thread.


all events occur in real time
I agree. Here's the link:
subject: Threads doubt??
It's not a secret anymore!