think in java - concurrency - task && thread
2014-06-25 00:00
399 查看
define a task:
# 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."
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 Thread&Concurrency(7): 深入理解Callable/Future(FutureTask)接口及其实现
- think in java - concurrency - Callable
- 《Java Concurrency in Practice》ch8 Applying Thread Pools
- think in java - concurrency - ThreadLocal
- Exception in thread "taskExecutor-4" java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProx
- think in java - concurrency - interruption
- Think in java 答案_Chapter 2_Exercise 9
- Think in java学习笔记-第4章 初始化和清除
- Think in java Stream 经典
- Thread In Java Technology
- Think in java 答案_Chapter 2_Exercise 5
- Think in java 学习手记(三)
- Think in java学习笔记-第5章 隐藏实施过程
- Java Thread in JVM
- Think in java &答案_Chapter 2_Exercise 2
- Think in java chapter's答案_Chapter 2_Exercise 3
- 解决Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
- [Think in Java 笔记] Final关键字
- Think In JavaII 中文版下载(链接已修正)
- Think in Java(12)-IO