当前位置: 技术问答>java相关
不太明白线程控制中的yield(),请高手给小弟见解一下,最好带例子?
来源: 互联网 发布时间:2015-03-07
本文导语: | Use the method Thread.yield() to give other threads of the same priority a chance to execute. If other threads at the same priority are runnable, yield places the calling thread into the runnable pool and allows another thread to run. If no...
|
Use the method Thread.yield() to give other threads of the same
priority a chance to execute. If other threads at the same priority are
runnable, yield places the calling thread into the runnable pool and
allows another thread to run. If no other threads are runnable at the
same priority, yield does nothing.
priority a chance to execute. If other threads at the same priority are
runnable, yield places the calling thread into the runnable pool and
allows another thread to run. If no other threads are runnable at the
same priority, yield does nothing.
|
According to JDK1.2 document, he said,
yield
public static void yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
e.g,
Reference to
-------------------------------------------------------------------------------
//: Daemons.java
// Daemonic behavior
import java.io.*;
class Daemon extends Thread {
private static final int SIZE = 10;
private Thread[] t = new Thread[SIZE];
public Daemon() {
setDaemon(true);
start();
}
public void run() {
for(int i = 0; i
yield
public static void yield()
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
e.g,
Reference to
-------------------------------------------------------------------------------
//: Daemons.java
// Daemonic behavior
import java.io.*;
class Daemon extends Thread {
private static final int SIZE = 10;
private Thread[] t = new Thread[SIZE];
public Daemon() {
setDaemon(true);
start();
}
public void run() {
for(int i = 0; i