Procházet zdrojové kódy

扩展core-concurrent的信号量工具,增加判断是否可用的方法

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi před 3 roky
rodič
revize
f741851544

+ 2 - 0
core-concurrent/src/main/java/com/qmth/boot/core/concurrent/model/Semaphore.java

@@ -10,4 +10,6 @@ public interface Semaphore {
     boolean tryAcquire();
 
     void release();
+
+    boolean isAvailable();
 }

+ 5 - 0
core-concurrent/src/main/java/com/qmth/boot/core/concurrent/service/impl/MemoryConcurrentService.java

@@ -101,6 +101,11 @@ public class MemoryConcurrentService implements ConcurrentService {
                         public void release() {
                             se.release();
                         }
+
+                        @Override
+                        public boolean isAvailable() {
+                            return se.availablePermits() > 0;
+                        }
                     };
                 });
             }

+ 5 - 0
data-redis/src/main/java/com/qmth/boot/redis/concurrent/RedisConcurrentService.java

@@ -78,6 +78,11 @@ public class RedisConcurrentService implements ConcurrentService, RedisConstant
             public void release() {
                 semaphore.release();
             }
+
+            @Override
+            public boolean isAvailable() {
+                return semaphore.availablePermits() > 0;
+            }
         };
     }