Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

does yield prevent thread execution?

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following will definitely stop a thread from executing
1. wait
2. notify
3.yield
4.suspend
5.sleep


Ans: 1 3 4 5


Does yield definitely stop executing? Incase there are no high priority threads in ready state, the same thread continues to run. how is yield a correct answer to this question?
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pramila:
Actually whenever there are equal priority thread then the running thread can volunteerally leave the running state. Hence, it stops its execution.But this behaviour of yield() method is not guarenteed...

I hope it helps...


Regards
Swapnil
[ June 23, 2006: Message edited by: Swapnil Trivedi ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is from the API.

yield

public static void yield()

Causes the currently executing thread object to temporarily pause and allow other threads to execute.
 
Swapnil Trivedi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
I am sorry for my last post..But I too am confused about this yield() method. I have one Question from Enthuware database that says that
"yield() does not necessarily put the calling thread on hold."

The Question was:

In which of the following cases a thread will definitely be alive but not running??
1. The thread has called wait().
2. The thread has issued sleep()
3. The thread calls yield()
4. A higher priority thread comes in ready to run state.
5. The thread is trying to enter a synchronized block and the monitor is not free.


Answer are: 1, 2 and 5

According to this concept the yield() does not stop execution. But according to Pramila's Question yield() definitely stops execution.

Can anybody explain....Thanks

Regards
Swapnil
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic