您的位置:首页 > 编程语言 > Java开发

think in java - concurrency - task && thread

2014-06-25 00:00 399 查看
define a task:

public class LiftOff implements Runnable {

protected int countDown = 10;

@Override
public void run() {
while (/* task is still necessary */ countDown -- > 0) {
System.out.println(countDown > 0 ? countDown : "Lift off!!");
Thread.yield();
}
}
}


# define a task

To define a Task, simply implementing Runnable and write a run() method to make the task do your bidding.

A task's run() method usually has some kind of loop that continues until the task is no longer necessary.

# Thread.yield()

It's a suggestion to thread scheduler that says, "I've done the important parts of my cycle and this would be a good time to switch to another task for a while."
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java think in concurrency