List of usage examples for java.util.concurrent.locks ReentrantLock ReentrantLock
public ReentrantLock(boolean fair)
From source file:com.ganji.cateye.flume.kestrel.KestrelRpcClient.java
License:asdf
public KestrelRpcClient() { stateLock = new ReentrantLock(true); connState = State.INIT;/*ww w.j a va2s . co m*/ threadCounter = new AtomicLong(0); // OK to use cached threadpool, because this is simply meant to timeout // the calls - and is IO bound. callTimeoutPool = Executors.newCachedThreadPool(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(KestrelRpcClient.this.sinkName + "-" + String.valueOf(threadCounter.incrementAndGet())); return t; } }); }
From source file:org.eclipse.ecr.core.storage.sql.LockManager.java
/** * Creates a lock manager using the given mapper. * <p>// w w w . j a va2s.c o m * The mapper will from then on be only used and closed by the lock manager. * <p> * {@link #shutdown} must be called when done with the lock manager. */ public LockManager(Mapper mapper, boolean clusteringEnabled) { this.mapper = mapper; this.clusteringEnabled = clusteringEnabled; serializationLock = new ReentrantLock(true); // fair caching = !clusteringEnabled; lockCache = caching ? new LRUCache<Serializable, Lock>(CACHE_SIZE) : null; }
From source file:org.nuxeo.ecm.core.storage.sql.LockManager.java
/** * Creates a lock manager using the given mapper. * <p>/*from w ww .j ava 2 s .co m*/ * The mapper will from then on be only used and closed by the lock manager. * <p> * {@link #shutdown} must be called when done with the lock manager. */ public LockManager(Mapper mapper, boolean clusteringEnabled) throws StorageException { this.mapper = mapper; this.connection = ((JDBCMapper) mapper).connection; this.clusteringEnabled = clusteringEnabled; serializationLock = new ReentrantLock(true); // fair caching = !clusteringEnabled; lockCache = caching ? new LRUCache<Serializable, Lock>(CACHE_SIZE) : null; try { connection.setAutoCommit(true); } catch (SQLException e) { throw new StorageException(e); } }
From source file:org.paxml.control.MutexTag.java
private Lock getLock(String lockName) { Lock lock = MAP.get(lockName); if (lock == null) { lock = new ReentrantLock(true); Lock existingLock = MAP.putIfAbsent(lockName, lock); if (existingLock != null) { lock = existingLock;/*w ww. j a v a 2 s . com*/ } } return lock; }
From source file:net.solarnetwork.node.io.rxtx.RxtxDataCollectorFactory.java
private Lock acquireLock() throws LockTimeoutException { log.debug("Acquiring lock on port {}; waiting at most {} {}", new Object[] { portIdentifier, timeout, unit }); synchronized (PORT_LOCKS) { if (!PORT_LOCKS.containsKey(portIdentifier)) { PORT_LOCKS.put(portIdentifier, new ReentrantLock(true)); }// w ww. ja v a 2 s . com Lock lock = PORT_LOCKS.get(portIdentifier); try { if (lock.tryLock(timeout, unit)) { log.debug("Acquired port {} lock", portIdentifier); return lock; } log.debug("Timeout acquiring port {} lock", portIdentifier); } catch (InterruptedException e) { log.debug("Interrupted waiting for port {} lock", portIdentifier); } } throw new LockTimeoutException("Could not acquire port " + portIdentifier + " lock"); }
From source file:io.tilt.minka.spectator.Spectator.java
public Spectator(final String hostPortArg, String logId) { this.logId = logId == null ? String.valueOf(hashCode()) : logId; this.shutdownLock = new ReentrantLock(true); // initialize user objects map this.mapObjects = new ConcurrentHashMap<>(); setHostPort(hostPortArg);//from ww w . ja va 2s .c o m // ensure finalization Runtime.getRuntime().addShutdownHook(new Thread(() -> leaveAllMeetings(true), SHUTDOWN_THREAD_NAME)); }
From source file:de.unirostock.sems.cbarchive.web.dataholder.Workspace.java
@JsonIgnore public synchronized Lock lockArchive(String archiveId) throws CombineArchiveWebException { if (archives.containsKey(archiveId) == false) throw new CombineArchiveWebException("No such archive."); ReentrantLock archiveLock = null; synchronized (this) { archiveLock = locks.get(archiveId); if (archiveLock == null) { archiveLock = new ReentrantLock(true); locks.put(archiveId, archiveLock); }//from w w w .j av a 2 s .c o m } try { if (archiveLock.tryLock(Fields.LOCK_ARCHIVE_TIMEOUT, TimeUnit.SECONDS) == false) throw new CombineArchiveWebException("Lock timeout."); } catch (InterruptedException e) { throw new CombineArchiveWebException("Lock interrupted.", e); } return archiveLock; }
From source file:net.sf.jasperreports.engine.fill.JRVirtualizationContext.java
private void initLock() { lock = new ReentrantLock(true); }
From source file:hudson.plugins.ec2.EC2RetentionStrategy.java
protected Object readResolve() { checkLock = new ReentrantLock(false); return this; }
From source file:org.alfresco.repo.workflow.WorkflowReportServiceImpl.java
private ReentrantLock acquireLock(String id) { synchronized (WorkflowReportServiceImpl.class) { String lockId = StringUtils.isBlank(id) ? "ReentrantLockDefaultLockId" : id; if (!taskAddingLock.containsKey(lockId)) { taskAddingLock.put(lockId, new ReentrantLock(true)); }//w w w . j a va 2 s . c om return taskAddingLock.get(lockId); } }