From 6018f9eb3da5fa45fc51e159a3b14fd7a7da8dc6 Mon Sep 17 00:00:00 2001 From: binghe001 <1028386804@qq.com> Date: Mon, 26 Sep 2022 16:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrent/policy/RejectHandler.java | 33 ++++++++++++ .../concurrent/queue/BlockingQueue.java | 53 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/policy/RejectHandler.java create mode 100644 mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/queue/BlockingQueue.java diff --git a/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/policy/RejectHandler.java b/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/policy/RejectHandler.java new file mode 100644 index 0000000..5e1c462 --- /dev/null +++ b/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/policy/RejectHandler.java @@ -0,0 +1,33 @@ +/** + * Copyright 2020-9999 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.binghe.concurrent.policy; + + +import io.binghe.concurrent.queue.BlockingQueue; + +/** + * @author binghe(公众号:冰河技术) + * @version 1.0.0 + * @description 拒绝策略接口 + */ +@FunctionalInterface +public interface RejectHandler { + + /** + * 拒绝任务回调接口 + */ + void reject(BlockingQueue queue, T task); +} diff --git a/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/queue/BlockingQueue.java b/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/queue/BlockingQueue.java new file mode 100644 index 0000000..2e85954 --- /dev/null +++ b/mykit-concurrent-threadpool/src/main/java/io/binghe/concurrent/queue/BlockingQueue.java @@ -0,0 +1,53 @@ +/** + * Copyright 2020-9999 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.binghe.concurrent.queue; + +import java.util.concurrent.TimeUnit; + +/** + * @author binghe(公众号:冰河技术) + * @version 1.0.0 + * @description 自定义阻塞队列接口 + */ +public interface BlockingQueue { + + /** + * 超时获取并移除队列数据 + */ + T poll(long timeout, TimeUnit timeUnit); + + /** + * 阻塞获取并移除队列数据 + */ + T take(); + + /** + * 向队列中添加元素 + */ + void put(T task); + + + /** + * 向队列中超时添加元素 + */ + boolean offer(T task, long time, TimeUnit timeUnit); + + /** + * 返回队列中元素的个数 + */ + int size(); + +} -- GitLab