• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread question from JavaCertificate.com

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some concerns regarding the following question from www.javacertificate.com:

The answers they have are 2 and 4. But I have a problem with answer 4. I thought time-slicing is used to prevent starvation between threads of the same priority level. If a thread at a high priority level contained an infinite loop, then isn't it true that a thread with a lower priority level would starve, even with time-slicing, since the thread scheduler would always choose the high priority thread to enter the running state?
So in my mind, the correct answer is 2. What do you all think?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Honestly, I think this question is pretty bad for a SCJP mock exam. The imlpementation of threading is based on the underlying OS. As a Java programmer, you can't really say what the threads will or won't do. There are all sorts of techniques one can use to implement time slicing so number 4 could be true on some systems while false on others.
I wouldn't worry too much about this question.
Corey
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java Threads by Scott Oaks & Henry Wong (O�Reilly) pages 133, 176-191 agrees with David.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Time-slicing insures that a higher-priority Thread never takes up all the CPU time.


Definition insure: arrange for compensation in the event of damage to or loss of property, or injury to or the death of someone, in exchange for regular payments to a company or government agency
Definition ensure: make certain that something shall occur or be the case
Time-slicing will never insure.
 
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the feedback that we have provided with the question, this is in line with what we are dscussing here.

Answer 2 and 4 are correct.
A thread is allowed to execute for a specified amount of time, after this period the running thread is placed in the ready state. This ensures that a higher priority Thread does not take all the CPU time and remain in the running state.
A time-sliced system (not Java system) divides the the CPU into time-slots and gives each of the threads a time slot in which to run.
The Java runtime does not implement (and therefore does not guarantee) time-slicing. However, some systems on which you can run Java do support time-slicing. Your Java programs should not rely on time-slicing as it may produce different results on different systems.
Notice that time-slicing makes no guarantees as to how often or in what order threads are scheduled to run.
 
David Willis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas,
Your feedback does nothing to address my issue with answer 4. My claim is that a time-slicing does not prevent a higher level thread from hogging CPU time. Rather, time-slicing systems allow threads with the same priority level to get an equal opportunity at being in the Running state. Shoot, I don't recall a guarantee by Java stating that after a thread is preempted by a time-slicing system, a different thread would be moved to the Running state. In this case, it is still possible (and therefore NOT guaranteed) that a thread could cause starvation of other threads of the same priority level. Of course, that's a platform specific threads implementation issue.
I agree with Corey, this question is not useful in making a student better prepared for the SCJP exam.
 
David Willis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Google's dictionary search:
in�sure ( P ) Pronunciation Key (n-shr)
v. in�sured, in�sur�ing, in�sures
v. tr.
1. a. To provide or arrange insurance for: a company that insures homeowners and businesses.
b. To acquire or have insurance for: insured herself against losses; insured his car for theft.
2. To make sure, certain, or secure.
So "insure" does work in the context, as would "assure". Most US english speakers would prefer "ensure" in this context.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

4. Time-slicing insures that a higher-priority Thread never takes up all the CPU time.


David you state that "a higher-priority Thread NEVER takes up all the CPU time"
I thought there are no guarantees when it comes to threads. You use the word never, is that not a guarantee?
 
David Willis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ryan, that's sort of my point. Java can't make a guarantee in regards to how threads are scheduled because Java can't control how an underlying system implements threads. Not only do I feel that answer 4 is wrong because Java can't make that guarantee, I also feel that answer 4 is wrong just by the definition of time-slicing and thread priority level, independent of Java.
 
Thomas De Vos
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for your valuable feedback. That is really appreciated. We are considering to change the wording of the question slightly so the question/answer and feedback becomes less ambigious.
reply
    Bookmark Topic Watch Topic
  • New Topic