wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread question from JavaCertificate.com Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread question from JavaCertificate.com" Watch "Thread question from JavaCertificate.com" New topic
Author

Thread question from JavaCertificate.com

David Willis
Greenhorn

Joined: Apr 16, 2003
Posts: 18
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?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Java Threads by Scott Oaks & Henry Wong (O�Reilly) pages 133, 176-191 agrees with David.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
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.
Thomas De Vos
stable boy
Ranch Hand

Joined: Apr 12, 2003
Posts: 425
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.


Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
David Willis
Greenhorn

Joined: Apr 16, 2003
Posts: 18
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

Joined: Apr 16, 2003
Posts: 18
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.
Ryan Wilson
Ranch Hand

Joined: Apr 16, 2003
Posts: 65
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

Joined: Apr 16, 2003
Posts: 18
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
Ranch Hand

Joined: Apr 12, 2003
Posts: 425
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread question from JavaCertificate.com
 
Similar Threads
yield
Thread priority (examulator.com)
Joining Thread, Explanation required
Thread priority and scheduling
whose responsible for scheduling Threads ???