This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Thread.yield()

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I was just looking at Dan's new beta version Thread topic exam and the 14th question is about yield() and Dan says
"The Thread.yield method might allow a lower priority thread to run." is not TRUE.
Isnt it a matter of the operating system to decide which thread to run? I have Simon Roberts' latest book and it mentions with a single sentence "Note that most schedulers do not stop the yielding thread from running in favor of a thread of lower priority." (page 230) He is not saying "All schedulers" but "most of them".
So, the above statement, should it be TRUE or FALSE?
Serdar
PS: Dan, you are really doing great job, thanks very much for your topic exams, they are really useful.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"JavaMania"-
Welcome to the JavaRanch!
Please adjust your displayed name to meet the JavaRanch Naming Policy.
You can change it here.
Thanks, and again welcome to the JavaRanch!
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Per Mughal, the Thread.yield() method will move current thread to ready_to_run state with any other threads already in that state. If it turns other thread(s) in that state have better priority than current thread, they will run first. After that current thread will resume.
sleep() and yield() are similar in nature except that sleep() will stop for specified time, while yield() will resume immediately after higher priority threads have run.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serdar,
Thank you for trying my beta version of the Thread exam. I have eagerly been awaiting some feedback.
I changed question 14 earlier today to remove the part of the question that refers to lower priority threads, so I'm surprised to see that you posted this question later in the day. The new version is as follows.


Which of the following is true?
a. The Thread.yield method might cause the thread to move to the blocking state.
b. The Thread.yield method might cause the thread to move to the ready state.
c. The same thread might continue to run after calling the Thread.yield method.
d. The Thread.yield method is a native method.
e. The behavior of the Thread.yield method is consistent from one platform to the next.
f. The Thread.sleep method causes the thread to move to the blocking state.
g. The Thread.sleep method causes the thread to move to the ready state.
h. None of the above.


The answers are b,c,d, and f.
The remark is as follows.


The thread.yield method is intended to cause the currently executing thread to move from the running state to the ready state and offer the thread scheduler an opportunity to allow a different thread to execute based on the discretion of the thread scheduler. The thread scheduler may select the same thread to run immediately or it may allow a different thread to run. The thread.yield method is a native method so the behavior is not guaranteed to be the same on every platform.


How does everyone feel about the above?
 
Serdar Ozturk
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan, first I took a copy of the exam on my harddisk and then I worked on it, that's way I posted the message after you corrected without knowing it had been corrected...
Serdar
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serdar,
Any exam that appears in the beta directory should be considered volatile so it is a good idea to simultaneously store both the question page and answer page on your disk. Otherwise, the answer page might not match the question page when you are ready to look at the answers. The most frequent change that I might make to a beta version of an exam is the addition of a few more questions at the end, but sometimes I'll change an existing question. For that reason, it is a good idea to store both the questions and answers at the same time as you have done.
Thank you for trying my exam.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,
I just wanted to know about the reference you're basing on your questions about threads.
Thx in advance.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of my exam is based on a variety of references such as The Java Language Specification, The Java 2 Platform, Standard Edition, v 1.4.0 API Specification, and the book "The Java Class Libraries Second Edition, Volume 1". I also use the supplemental version of that book for the Java 2 platform. Of course I also use the exam objectives. To cover topics that focus on the use of classes such as those in java.lang or java.util I will also look through the source code to get a better idea of how the methods are implemented. My references are not limited to the above.
The Java Class Libraries book mentioned above is extremely useful. It is similar to the API Specification but it contains detailed explanations on how to use each method of each class. I often develop exam questions just by reading through the explanations and then I write questions to demonstrate the capabilities and limitations of the classes and methods.
You may have noticed that my signature does not include "SCJP". That's because I have been developing my exam by publishing the test programs that I write to verify what I have learned in preparation for taking the real exam myself. Before I started working on my exam, I had already completed one exam study guide. After taking some of the practice exams available on the web, I realized that I was still weak in some areas. To gain further experience in those areas, I started writing test programs to verify my understanding of the material. At that time, I was also studying XML, XSLT, and JDOM and I wanted to do something interesting with those technologies. I thought that it might be fun to put my test programs into an XML document and then use JDOM to organize them into a variety of exam sets and then use XSLT to transform them into HTML so that I could publish them on the web. In other words, I have developed my exam to enhance my own understanding of Java and a variety of XML technologies.
That last paragraph was a little bit of a rabbit trail but I'll try to get back on topic here. To cover a topic such as control flow or operators the Java Language Specification is about the only reference necessary. To cover threads, more is needed beyond the Java Language Specification. The beta exam for threads that I recently uploaded is not yet complete. (I should really call it an alpha version.) Most of the questions are based on information that is available in The Java Class Libraries book mentioned above. You have probably noticed that the questions are very basic. For example, many simply ask which class declares a particular method, which methods are static, which throw a checked exception, etc. These are all details that are critical to passing the exam, but they are not questions that will generate a lot of controversy. That's probably why I have not yet received much feedback on the exam even though it has had more than forty hits.
Today, my thread exam has 31 questions, but many more are needed to cover the material. I hope that you will find the exam useful when it is complete.
Anyone interesting in trying the beta version of my thread exam can find it at the following.
http://www.danchisholm.net/beta/threads.html
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan, referring to the question above, the API says that Thread.yield() is public static void. There is no mention of it being native, and I wouldn't expect a question requiring knowledge of that fact to turn up in the exam.
-Barry
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:
Dan, referring to the question above, the API says that Thread.yield() is public static void. There is no mention of it being native, and I wouldn't expect a question requiring knowledge of that fact to turn up in the exam.
-Barry


Barry,
Thank you for the feedback. I agree that the question was not very good so I just replaced it with a new one.
I was looking at the source code for the Thread class when I added that "native" question to previous version of the thread exam so I have no doubt that it really is native.

However, your statement is also correct. The API Specification only states that it is public, static, void. Is it possible that the decision to implement a method using native code is considered an implementation issue and is therefore beyond the scope of the specification?
I agree that the "native" question is not a good one so I just replaced it with a new one that asks if the method is static.
I just added five more questions to the end of the threads exam at the following URL.
http://www.danchisholm.net/beta/threads.html
The new questions are all related to the use of the Thread.interrupt and Thread.interrupted methods. The new questions are numbered 32 through 36.
Thanks again for the feedback Barry.
 
Bring out your dead! Or a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!