Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q on Kathy's Mock Test (Tpoic:Threads)

 
Reshma Shanbhag
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Which two donot cause a Thread to stop being the currently running thread?

A. calling the join() on a live thread
B. calling the sleep()
C. calling the wait()
D. calling the notify()
E. Entering an unlocked, sunchronized block of code.
Are the options A & E correct ?
Calling a notify() or notifyAll() releases the lock on the thread?
Help me
reshma
[ April 02, 2003: Message edited by: Reshma Pai ]
[ April 02, 2003: Message edited by: Reshma Pai ]
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
join can result in the current thread's detention only if the thread on which join was called has started and not ended yet.
sleep and wait will always cause current thread's detention.
notify wil never cause it.
a synchronized block whose lock is not hold by any other thread will not prevent a thread from executing it.
wait releases the monitor, notify not.
You can find more information in the Java Tutorial at java.sun.com and the API.
[ April 02, 2003: Message edited by: Jose Botella ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Four methods cause a Thread to back out of running: Thread.sleep, Thread.yield, wait and join. The answer is therefore D and E.
 
Reshma Shanbhag
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jose and Roger for helping me solve the question.

Reshma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic