From e6da85f4ac13bdfe6b246009bd6b4eedc1ab1334 Mon Sep 17 00:00:00 2001 From: 10km <10km0811@sohu.com> Date: Wed, 25 Sep 2019 12:21:27 +0800 Subject: [PATCH] =?UTF-8?q?ELocker=E5=AE=9E=E7=8E=B0=20Closeable=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=8C=E6=94=AF=E6=8C=81jdk7=20try-with-resources?= =?UTF-8?q?=20=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/coody/framework/elock/ELocker.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/coody/framework/elock/ELocker.java b/src/main/java/org/coody/framework/elock/ELocker.java index 5a824ac..f6e408f 100644 --- a/src/main/java/org/coody/framework/elock/ELocker.java +++ b/src/main/java/org/coody/framework/elock/ELocker.java @@ -1,5 +1,7 @@ package org.coody.framework.elock; +import java.io.Closeable; + import org.coody.framework.elock.pointer.ELockerPointer; /** @@ -8,7 +10,7 @@ import org.coody.framework.elock.pointer.ELockerPointer; * @author Coody * */ -public class ELocker { +public class ELocker implements Closeable{ /** @@ -34,4 +36,21 @@ public class ELocker { ELockerPointer.fallOut(key); } + private final String key; + + private ELocker(String key) { + super(); + this.key = key; + } + + @Override + public void close() { + unLock(key); + } + + public static ELocker locker(String key, Integer expireSecond) throws InterruptedException { + lock(key, expireSecond); + return new ELocker(key); + } + } -- Gitee