thread yield

Posted on 2011-04-26
Last Modified: 2012-05-11
>>Which of the following statements are true?

1) A higher priority Thread will prevent a lower priorty Thread from getting any access to the CPU.

2) The yield method only allows any higher priority priority thread to execute.

3) The Thread class has a static method called yield

4) Calling yield with an integer parameter causes it to yield for a specific time.


3) The Thread class has a static method called yield

A call to yield can allow any waiting thread to execute depending on the scheduling system of the underlying operating system. There is no version of yield that takes an integer parameter. Weather a higher priority thread gets CPU time than a lower priority thread is platform dependent and cannot be certain.

I read above question and answer. It is not clear to me. Why the yield method of thread class is static where as other methods of thread are not static,

Any ideas, resources, links, sample code highly appreciated. thanks in advance.
Question by:gudii9
    LVL 92

    Accepted Solution

    Because it operates on the current thread. Only the currently running thread can be told to yield.
    LVL 92

    Expert Comment

    LVL 7

    Author Comment

    i was reading the link

    >>>But if another thread were able to invoke sleep on this thread, it would have no way of knowing what section of code was being executed, and whether or not it's a good time for it. In general, it's better to have threads put themselves to sleep. If you want one thread to be able to tell another to go to sleep, you need to devise a means of communication between the threads, and have the target thread check periodically to see if it's been requested to go to sleep.

    which one is target thread. please advise
    LVL 92

    Expert Comment

    the target thread is the one you want to put to sleep

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    Problem to setup 18 65
    basic hardware to learn oop advanced design patterns 3 49
    countAbc challenge 9 35
    countHi2 challenge 7 30
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This video teaches viewers about errors in exception handling.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now