• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads doubt??

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
S Thiyanesh
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I'm right that option 1 is also correct??
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

we can argue about answer one:
Thread t = new Thread();
t.yield();
and
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.


Yours,
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic