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."