List of usage examples for java.util.concurrent.locks ReentrantLock unlock
public void unlock()
From source file:RefinableHashSet.java
/** * Synchronize before adding, removing, or testing for item * @param x item involved/*from ww w. jav a2 s.c o m*/ */ @Override public void acquire(T x) { boolean[] mark = { true }; Thread me = Thread.currentThread(); Thread who; while (true) { do { // wait until not resizing who = owner.get(mark); } while (mark[0] && who != me); ReentrantLock[] oldLocks = this.locks; int myBucket = Math.abs(x.hashCode() % oldLocks.length); ReentrantLock oldLock = oldLocks[myBucket]; oldLock.lock(); // acquire lock who = owner.get(mark); if ((!mark[0] || who == me) && this.locks == oldLocks) { // recheck return; } else { // unlock & try again oldLock.unlock(); } } }
From source file:org.commoncrawl.service.parser.client.Dispatcher.java
public void nodeOnline(ParserNode theNode) throws IOException { final ReentrantLock lock = this.lock; lock.lock();/*from ww w . j ava2s. co m*/ try { boolean ok = _onlineNodes.add(theNode); assert ok; notEmpty.signal(); } finally { lock.unlock(); } }
From source file:org.commoncrawl.service.parser.client.Dispatcher.java
public void nodeStatusChanged(ParserNode theNode) { final ReentrantLock lock = this.lock; lock.lock();/*from w ww.j av a2s . c o m*/ try { _onlineNodes.remove(theNode); _onlineNodes.add(theNode); notEmpty.signal(); } finally { lock.unlock(); } }
From source file:com.streamsets.datacollector.io.DataStore.java
/** * This method must be used after completing the write to output stream which was obtained by calling the * {@link #getOutputStream()} method./*from w w w . j a v a2 s . c om*/ * * If the write operation was successful, then this method must be called after calling the * {@link #commit(java.io.OutputStream)} method. Otherwise it must be called after calling the {@link #close()} on the * output stream. * * Example usage: * * DataStore dataStore = new DataStore(...); * try (OutputStream os = dataStore.getOutputStream()) { * os.write(..); * dataStore.commit(os); * } catch (IOException e) { * ... * } finally { * dataStore.release(); * } * */ public void release() { ReentrantLock lock; synchronized (DataStore.class) { lock = FILE_LOCKS.remove(file); } if (lock != null) { LOG.trace("Releasing the lock for '{}'", file); lock.unlock(); LOG.trace("Released the lock for '{}'", file); } }
From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java
public void close() throws SQLException { //TODO - Prevent unuathorized call final ReentrantLock l = lock; l.lock();/* w w w. j a va 2s. co m*/ try { try { unregisterMBean(); } catch (final Exception ignored) { // no-op } super.close(); } finally { l.unlock(); } }
From source file:org.apache.openejb.resource.jdbc.dbcp.BasicDataSource.java
public void setDefaultTransactionIsolation(final String s) { final ReentrantLock l = lock; l.lock();//from ww w.ja v a2 s.com try { if (s == null || s.equals("")) { return; } final int level = IsolationLevels.getIsolationLevel(s); super.setDefaultTransactionIsolation(level); } finally { l.unlock(); } }
From source file:io.tilt.minka.business.impl.SemaphoreImpl.java
private void release_(Action action, Action cause) { Validate.notNull(action);/*from w w w. ja va 2 s . co m*/ // first unlock the dependencies so others may start running if (cause == null) { // only when not rolling back to avoid deadlock final List<Action> group = rules.get(action).getRelated(SIBLING); if (group != null) { group.forEach(a -> release_(a, action)); } } switch (action.getScope()) { case LOCAL: // then unlock the main lock ReentrantLock lock = g(action); if (lock == null) { logger.error("{}: Locks not implemented for action: {} ", getClass().getSimpleName(), action); } else { if (logger.isDebugEnabled() && cause != null) { logger.debug("{}: {} is Releasing: {}", getClass().getSimpleName(), cause, action); } lock.unlock(); } break; case GLOBAL: locks.releaseDistributedLock(nameForDistributedLock(action, null)); break; } }
From source file:org.eclipselabs.etrack.server.web.storage.AbstractStorageResource.java
@Override protected Representation doConditionalHandle() throws ResourceException { ReentrantLock lock = null; synchronized (locks) { lock = locks.get(getReference().toString()); if (lock == null) { lock = new ReentrantLock(); locks.put(getReference().toString(), lock); }/*from ww w .j av a2 s . com*/ } lock.lock(); try { Representation result = super.doConditionalHandle(); return result; } finally { lock.unlock(); } }
From source file:com.zimbra.cs.db.SQLite.java
private void releaseMboxDbLock(Integer mboxId) { if (mboxId != null) { ReentrantLock lock = null; lock = lockMap.get(mboxId);/*from w w w . ja v a 2 s. c o m*/ if (lock != null && lock.isHeldByCurrentThread()) { lock.unlock(); ZimbraLog.dbconn.trace("unlocked mbox %d", mboxId); } } }
From source file:org.apache.openejb.resource.jdbc.dbcp.BasicManagedDataSource.java
public Logger getParentLogger() throws SQLFeatureNotSupportedException { final ReentrantLock l = lock; l.lock();//from www .j a v a2 s . com try { if (null == this.logger) { this.logger = (Logger) DataSource.class.getDeclaredMethod("getParentLogger") .invoke(super.dataSource); } return this.logger; } catch (final Throwable e) { throw new SQLFeatureNotSupportedException(); } finally { l.unlock(); } }