• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Preventing a thread from executing

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a javabeat mock exam i found the following question
1 Which of the following can prevent a thread from executing?
(1) A call to its pause method
(2) A call to Thread.yield()
(3) Another thread is given higher priority
(4) A call to its halt() method

the answers are given as 2 and 3.
But according to me Thread.yield() method does not always prevent a thread from executing. It will move from executing state to ready state and the rest is platform dependent.
How can we say that 3 is a correct answer. Is't the priority implementation platform dependent.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Sreeram Desigan ,

(2) A call to Thread.yield()

is correct



(3) Another thread is given higher priority

but i am not sure about this
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thread.yield method does not guarantee that it will prevent the currently executing thread from execution.So, this is wrong.

I used to think that platform-dependent issues should not be considered as correct ans. as it changes from one system to another.

Someone else plz help on 2nd option.

Asha
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question reads
"CAN prevent a thread from executing", and not WILL prevent a thread from executing.
Therefore option 2 is correct. It is not guaranteed, but it is possible, that yield takes a thread out of the running state.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic