From 414e2eaa40920ea9f9748804e51052b043afb0ca Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 1 Aug 2020 12:59:18 +0000 Subject: [PATCH] implement AutoCloseable in Locker --- app/src/main/java/net/ktnx/mobileledger/utils/Locker.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java b/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java index 515b314c..474ce83f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Locker.java @@ -19,7 +19,7 @@ package net.ktnx.mobileledger.utils; import java.util.concurrent.locks.ReentrantReadWriteLock; -public class Locker { +public class Locker implements AutoCloseable { private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); public LockHolder lockForWriting() { ReentrantReadWriteLock.WriteLock wLock = lock.writeLock(); @@ -35,4 +35,9 @@ public class Locker { rLock.lock(); return new LockHolder(rLock); } + @Override + public void close() { + lock.readLock().unlock(); + lock.writeLock().unlock(); + } } -- 2.39.5