本文采用知识共享 署名-相同方式共享 4.0 国际 许可协议进行许可。
访问 https://creativecommons.org/licenses/by-sa/4.0/ 查看该许可协议。
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.LinkedBlockingQueue;
@Slf4j
public class CatExecutorService {
private final LinkedBlockingQueue<Runnable> threadQueue = new LinkedBlockingQueue<>();
public CatExecutorService() {
log.info("Starting CatPool ...");
new Thread(
() -> {
while (true) {
try {
Runnable take = threadQueue.take();
take.run();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
},
"CatThreadPool")
.start();
log.info("Started CatPool.");
}
public void submit(Runnable runnable) {
if (null == runnable) return;
synchronized (this) {
threadQueue.add(runnable);
}
}
}