aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Dan Watch "Dan New topic
Author

Dan's exam question

Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Question 5
Which of the following will force a thread to move into the Not-Runnable state?
a. Thread.yield method.
b. Thread.sleep method.
c. Thread.join method.
d. Object.wait method.
e. By blocking on IO.
f. Unsuccessfully attempting to acquire a lock on an object.
g. None of the above.
I selected d,e,f but the answer is b c d e f. Well what I think is that if Thread.sleep() is called with an argument of 0 it will not cause the thread to get into the Not-Runnable state. If Thread.join is used on a thread and if that thread has already completed then also I guess that the thread will not get into the Not-Runnable state. Though I also selected the Object.wait() method how would it behave when called with an argument of 0.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
I have the same doubts for question no. 15. I am now giving the Dan's exam so if i find some doubts I will post it.
[ May 16, 2003: Message edited by: Anupam Sinha ]
preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
my answer to this question was sleep, wait, block on IO, unsuccessfull attempt to acquire lock.... but I fail to understand why join()?
definitely not yield(), coz I realised that yield() may cause the thread to yield to another or may be bought back to running state by the scheduler...
join() is where the main thread waits for the currently referenced thread to die... the only reason , why join may cause the thread to be non -runnable is becoz it may be waiting or blocked on IO or one of the above reasons... Dan can you explain this please
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
join() is where the main thread waits for the currently referenced thread to die... the only reason , why join may cause the thread to be non -runnable is becoz it may be waiting or blocked on IO or one of the above reasons... Dan can you explain this please

Yes join may cause a thread to wait if the thread is in the above states but it may also wait if the thread is not in the above states. Simply if the the thread on which join is invoked is doing some work but is not in the above mentioned states.
[ May 18, 2003: Message edited by: Anupam Sinha ]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I fail to understand why join()

The instance join method is used to make one Thread (let's call it A) wait for another (let's call it B). So, when A invokes B.join(), A becomes Not-Runnable.
Note that join does not cause A to relinquish the locks it holds on objects.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Roger
What you said is true. But what if thread A's A.join() is invoked after the thread A has completed its run method. That is from thread B invokes A.join() but before this statement is executed A has already completed its work. Secondly what if you invoke A.join(0) with an argument of 0.
Hope that helps.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
But what if thread A's A.join() is invoked after the thread A has completed its run method. That is from thread B invokes A.join() but before this statement is executed A has already completed its work.

If A's run method has finished, then A is dead and cannot be resurrected. You can still invoke A's methods, but they will run in another thread.
Secondly what if you invoke A.join(0) with an argument of 0.

join(0) is the same as join(), ie causes the thread to wait forever. If B completes, then the thread scheduler can put A into the running state again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dan's exam question
 
Similar Threads
Thread.yield
Thread Question!
thread question of Dan Chisholm mock exam
Dan's: Blocked vs Waiting - possible mistake
Doubt with join() method