think in java - concurrency - task && thread

define a task:
java

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 taskide

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

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

    

# Thread.yield()code

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

相關文章
相關標籤/搜索