导入hutool工具

maven项目导入,下面三种导入方式

cn.hutool

hutool-all

5.4.0

Gradle项目导入

compile 'cn.hutool:hutool-all:5.5.0'

64311a338913

image.png

下面是实现代码

import cn.hutool.http.HttpRequest;

import cn.hutool.json.JSONUtil;

import java.util.HashMap;

import java.util.Map;

import java.util.concurrent.ArrayBlockingQueue;

import java.util.concurrent.ThreadPoolExecutor;

import java.util.concurrent.TimeUnit;

public class JianShuReadNum {

private static final int CORE_POOL_SIZE = 4;

private static final int MAX_POOL_SIZE = 10;

private static final int QUEUE_CAPACITY = 100;

private static final Long KEEP_ALIVE_TIME = 1L;

public static void main(String[] args) {

ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(

CORE_POOL_SIZE,

MAX_POOL_SIZE,

KEEP_ALIVE_TIME,

TimeUnit.SECONDS,

new ArrayBlockingQueue<>(QUEUE_CAPACITY),

new ThreadPoolExecutor.AbortPolicy()

);

String articleId = "7058fc449cb4";//文章id

//开启4个线程执行

for (int i = 0; i < CORE_POOL_SIZE; i++) {

poolExecutor.execute(() -> {

int num = 10000;//每个线程刷取的阅读量

for (int j = 0; j < num; j++) {

System.out.println(Thread.currentThread()+"====="+j);

Map map = new HashMap<>();

map.put("fuck",1);

HttpRequest.post("https://www.jianshu.com/shakespeare/notes/"+articleId+"/mark_viewed")

.header("Host", "www.jianshu.com")

.header("Origin", "https://www.jianshu.com")

.header("Referer", "https://www.jianshu.com/p/"+articleId)

.body(JSONUtil.toJsonStr(map), "application/json")

.execute();

}

});

}

poolExecutor.shutdown();

while (!poolExecutor.isTerminated()) {

}

System.out.println("线程执行完成");

}

}

代码中的articleId变量替换成你的文章id,不知道自己文章id的可以打开自己的文章,浏览器地址栏斜杠后的字符串就是你的文章id

64311a338913

image.png

点赞支持一下吧!

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐