1 Star 0 Fork 0

schwarizard / Chapter 9

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
RequestQueue 801 Bytes
一键复制 编辑 原始数据 按行查看 历史
schwarizard 提交于 2016-04-03 21:25 . new file
import java.util.*;
interface Request {
void execute();
}
public class RequestQueue {
public static void main(String[] args) {
Queue requests = new LinkedList();
offerRequestTo(requests);
process(requests);
}
static void offerRequestTo(Queue requests) {
for(int i = 1;i < 6;i++) {
Request request = new Request() {
public void execute() {
System.out.printf("处理数据 %f%n", Math.random());
}
};
requests.offer(request);
}
}
static void process(Queue requests) {
while (requests.peek() != null) {
Request request = (Request) requests.poll();
request.execute();
}
}
}
Java
1
https://gitee.com/schwarizard/Chapter-9.git
git@gitee.com:schwarizard/Chapter-9.git
schwarizard
Chapter-9
Chapter 9
master

搜索帮助