这段代码中应用一个 Map 来存储所有事宜,供给两个办法:注册一个事宜、履行某个事宜。
壅塞队列存储请求响应
编码要点
- public class Scheduler {
- private BlockingQueue<Request> pending = new LinkedBlockingQueue<>();
- private BlockingQueue<Response> result = new LinkedBlockingQueue<>();
- public void addRequest(Request request) {
- try {
- this.pending.put(request);
- } catch (InterruptedException e) {
- log.error("向调剂器添加 Request 掉足", e);
- }
- }
- public void addResponse(Response response) {
- try {
- this.result.put(response);
- } catch (InterruptedException e) {
- log.error("向调剂器添加 Response 掉足", e);
- }
- }
- public boolean hasRequest() {
- return pending.size() > 0;
- }
- public Request nextRequest() {
- try {
- return pending.take();
- } catch (InterruptedException e) {
- log.error("大年夜调剂器获取 Request 掉足"
推荐阅读
年前最后一场技巧盛宴 | 1月27日与京东、日记易技巧大年夜咖畅聊智能化运维成长趋势!PC主机重要的散热方法分为风冷和水冷,然则信赖不少玩家据说过“油冷”,就是应用矿物油不导电的特点,将>>>详细阅读
本文标题:设计和实现一款轻量级的爬虫框架
地址:http://www.17bianji.com/lsqh/40337.html
1/2 1