File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread.yield() 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 "Thread.yield()" Watch "Thread.yield()" New topic
Author

Thread.yield()

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
Given a reference called
t
to a class which extends Thread, which of the following will cause the currently executing Thread to give up cycles to allow another thread to execute.


1) t.yield();
2) Thread.yield();
3) yield(100); //Or some other suitable amount in milliseconds
4) yield(t);

1.I worked on the above program,that showed 1 and 2 answers are correct.But i want to verify the answer since Threads topic is new for me.is that correct answers are 1 and 2.Please let me know.

2.Is yield() is not a guaranted?

[ February 16, 2007: Message edited by: Shiva Mohan ]
[ February 16, 2007: Message edited by: Shiva Mohan ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
There is no version of yield in Thread which allows you to specify a time or Thread instance.

The documentation for yield says

Causes the currently executing thread object to temporarily pause and allow other threads to execute.

The reason that both 1 and 2 will work is that yield is a static method in Thread.

So you can call the method using an instance of Thread, but it is irrelevant which Thread instance calls it. The currently executing thread is the thread that pauses.
[ February 16, 2007: Message edited by: Keith Lynn ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread.yield()
 
Similar Threads
NullPointerException
default
Marcus Green #3 Question 44
Threads & Locks??
instance of operator