Archived
0

Prefab for actual resource lock

This commit is contained in:
Daniil
2018-08-03 21:14:28 +07:00
parent 38f69c3dfa
commit 227deac6f0

View File

@@ -0,0 +1,43 @@
package mc.core.events.v3.lock;
import mc.core.events.v3.runner.ExecutorThread;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
public class CustomReentrantLock extends ReentrantLock {
private void checkThread() {
if (!(Thread.currentThread() instanceof ExecutorThread))
throw new RuntimeException("Unable to obtain this resource outside Async Executor");
}
@Override
public void lock() {
checkThread();
super.lock();
}
@Override
public void lockInterruptibly() throws InterruptedException {
checkThread();
super.lockInterruptibly();
}
@Override
public boolean tryLock() {
checkThread();
return super.tryLock();
}
@Override
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
checkThread();
return super.tryLock(timeout, unit);
}
@Override
public void unlock() {
checkThread();
super.unlock();
}
}