diff --git a/src/main/java/org/coody/framework/elock/ELocker.java b/src/main/java/org/coody/framework/elock/ELocker.java index 5a824ac290064ffda3238b9a3609a3daa28e57fe..f6e408f8929a7dfde0edb5e77d7d4e2e58e88895 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); + } + }