yield thread ()

Is a local method, abandon the current CPU resources, back to runnable state.

    /**
     * A hint to the scheduler that the current thread is willing to yield
     * its current use of a processor. The scheduler is free to ignore this
     * hint.
     *
     * <p> Yield is a heuristic attempt to improve relative progression
     * between threads that would otherwise over-utilise a CPU. Its use
     * should be combined with detailed profiling and benchmarking to
     * ensure that it actually has the desired effect.
     *
     * <p> It is rarely appropriate to use this method. It may be useful
     * for debugging or testing purposes, where it may help to reproduce
     * bugs due to race conditions. It may also be useful when designing
     * concurrency control constructs such as the ones in the
     * {@link java.util.concurrent.locks} package.
     */
    public static native void yield();

Thread.yield Java thread () method, translated thread concessions. After the name suggests, that when a thread using this method, it will time out to make himself executed by the CPU,

Let yourself or other threads running, is to pay attention to their own or other threads running, not simply to give other threads.

        The role of yield () is a concession. It allows the current thread "running state" into a "ready state", so that other waiting threads with the same priority access to executive power; however, does not guarantee

Certificate after the current thread calls yield (), the other with the same priority thread will be able to get the implementation right; also possible that the current thread has entered into the "operating state" continues to run!

      For example: a group of friends in the queue on the bus, turn to Yield when he suddenly said: I do not want to go up, to let everyone on the bus race. Then everyone rushed to a bus,

There may be other people get on the bus, there may be Yield to on the bus.

     But there is a thread priority, the higher the priority of people, will be able to first get on it? This is not necessarily the probability of high priority just the first person on the train is a little of it,

The first final on the train, there are likely to be the lowest priority of people. And so-called priority execution, execution is a large number of times in order to reflect out.

 

Guess you like

Origin www.cnblogs.com/DDiamondd/p/11290942.html