org.postgresql.jdbc.ResourceLock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbc-yugabytedb Show documentation
Show all versions of jdbc-yugabytedb Show documentation
Java JDBC 4.2 (JRE 8+) driver for YugaByte SQL database
The newest version!
/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.jdbc;
import java.util.concurrent.locks.ReentrantLock;
/**
* Extends a ReentrantLock for use in try-with-resources block.
*
* Example use
* {@code
*
* try (ResourceLock ignore = lock.obtain()) {
* // do something while holding the resource lock
* }
*
* }
*/
public final class ResourceLock extends ReentrantLock implements AutoCloseable {
/**
* Obtain a lock and return the ResourceLock for use in try-with-resources block.
*/
public ResourceLock obtain() {
lock();
return this;
}
/**
* Unlock on exit of try-with-resources block.
*/
@Override
public void close() {
this.unlock();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy