httpcomponents-asyncclient

ThreadFactory & ThreadGroup

本秂侑毒 提交于 2020-03-01 23:56:21
原本想给 多线程任务 做一个挂起(暂停)功能,然后配合 httpcomponents-asyncclient 并发测试,结果意外令人汗颜,竟然CPU占用100%。。。 使用VisualVM观察CPU抽样,发现 org.apache.http.impl.nio.reactor.AbstractIOReactor.execute() 方法总是占用大部分CPU,然而没调用挂起操作时却一切正常。 这挂起操作的其中一环需要中断线程,这些线程均出产自自定义ThreadFactory : public class GroupThreadFactory implements ThreadFactory { private final ThreadGroup group; private final AtomicInteger threadNumber; public GroupThreadFactory() { this.group = new ThreadGroup("WorkerGroup"); this.threadNumber = new AtomicInteger(1); } public Thread newThread(Runnable r) { Thread t = new Thread(null, r, "pool-thread-" + threadNumber