java.lang.Thread utilizes which of the following methods to relinquish the thread instance's processing slot to another thread? a. sleep()--true b. wait()//Objects method otherwise true c. notify() //Objects method otherwise true How are thread priorities and thread scheduling related? a. they aren't--they are related b. it depends on the thread-scheduling algorithm used to implement the JVM -true c. thread priority is specified when a thread is to be executed next. ---false specified on creation d. thread priority is used to determing the next thread to execute from the waiting thread pool. -true
I think notify() is incorrect in the first question - aside from the fact that it's an Object method (good call), it doesn't actually do anything to relinquish the thread processing slot - it just tells another thread to get ready for when it does relinquish the slot. The thread calling notify() must already have a lock on the object used to invoke notify(), and the thread being notified will need that same lock itself to resume execution (because it could only call wait() from code synchronized on that object). So the notified thread can't do anything until the notifying thread does something else to relinquish the thread - at the very least, it has to exit the synchronized code block. After that it could just finish executing or call Thread.yield() - otherwise it's up to the thread scheduling algorithm to decide when (or if) to switch over to the waiting thread. I agree with your other answers though.
Thread priority is set AFTER the thread is created using setPriority() method and not during creation. Am I right?
Joined: Jan 30, 2000
Ah, I didn't notice that. You are correct, ShreeDevi. On creation, it gets default priority (you can't set it yourself on creation). After that, you can set it whenever you want. Looking back at the original statement: c. thread priority is specified when a thread is to be executed next. I'm not really sure what it was meant to mean. You could specify the priority just before it executes, but you don't have to. And in a multithreaded system you often don't really know when a given thread will execute anyway. So I'll say false just because the statement makes no sense.
Jim: I had that question wrong in Bill Brogden's JAVA 2 EXAM CRAM book. That's because: "When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread,"
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD