Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Thread priority (

Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this question on examulator

Which of the following statements are true?
Select 1 option

1) A higher priority Thread will prevent a lower priorty Thread from getting any access to the CPU.
2) The yield method only allows any higher priority priority thread to execute.
3) The Thread class has a static method called yield
4) Calling yield with an integer parameter causes it to yield for a specific time.

The correct answer was 3.
I think 1 and 3 should be the correct answer
This is a quote from Kathy & Berts book

The closest thing to a guarantee is that at any given time, when a thread is running it will usually not have a lower priority than any thread in the runnable state. If a low-priority thread is running when a high-priority thread enters runnable, the JVM will preempt the running low-priority thread and put the high-priority thread in.

Could someone please tell me if 1 is the correct answer also.
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My problem with 1 is that it is worded as an absolute. Exactly what happens is up to the JVM thread management and what the higher priority Thread is trying to do.
Note the "usually" in the quoted passage.
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic