All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.postgresql.jdbc.ResourceLock Maven / Gradle / Ivy

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