diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueue.java b/hutool-core/src/main/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueue.java
new file mode 100644
index 000000000..a22f93097
--- /dev/null
+++ b/hutool-core/src/main/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueue.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 cn.hutool.core.collection;
+
+import cn.hutool.core.thread.SimpleScheduler;
+import cn.hutool.core.util.RuntimeUtil;
+
+import java.util.Collection;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 内存安全的{@link LinkedBlockingQueue},可以解决OOM问题。
+ * 原理是通过Runtime#freeMemory()获取剩余内存,当剩余内存低于指定的阈值时,不再加入。
+ *
+ *
+ * 此类来自于: + * Apache incubator-shenyu + *
+ * + * @author incubator-shenyu + * @since 6.0.0 + */ +public class MemorySafeLinkedBlockingQueue
- * see: http://blog.csdn.net/partner4java/article/details/9417663
+ * see: http://blog.csdn.net/partner4java/article/details/9417663
*
* @param blockingCoefficient 阻塞系数,阻塞因子介于0~1之间的数,阻塞因子越大,线程池中的线程数越多。
* @return {@link ThreadPoolExecutor}
@@ -660,10 +661,10 @@ public class ThreadUtil {
* @param initialDelay 初始延迟,单位毫秒
* @param period 执行周期,单位毫秒
* @param fixedRateOrFixedDelay {@code true}表示fixedRate模式,{@code false}表示fixedDelay模式
- * @return {@link ScheduledThreadPoolExecutor}
+ * @return {@link ScheduledExecutorService}
* @since 5.5.8
*/
- public static ScheduledThreadPoolExecutor schedule(final ScheduledThreadPoolExecutor executor,
+ public static ScheduledExecutorService schedule(final ScheduledExecutorService executor,
final Runnable command,
final long initialDelay,
final long period,
@@ -685,10 +686,10 @@ public class ThreadUtil {
* @param period 执行周期
* @param timeUnit 时间单位
* @param fixedRateOrFixedDelay {@code true}表示fixedRate模式,{@code false}表示fixedDelay模式
- * @return {@link ScheduledThreadPoolExecutor}
+ * @return {@link ScheduledExecutorService}
* @since 5.6.5
*/
- public static ScheduledThreadPoolExecutor schedule(ScheduledThreadPoolExecutor executor,
+ public static ScheduledExecutorService schedule(ScheduledExecutorService executor,
final Runnable command,
final long initialDelay,
final long period,
diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java
new file mode 100644
index 000000000..8b1cbd148
--- /dev/null
+++ b/hutool-core/src/test/java/cn/hutool/core/collection/MemorySafeLinkedBlockingQueueTest.java
@@ -0,0 +1,13 @@
+package cn.hutool.core.collection;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class MemorySafeLinkedBlockingQueueTest {
+
+ @Test
+ public void offerTest(){
+ final MemorySafeLinkedBlockingQueue