List of usage examples for java.util.concurrent.locks ReentrantReadWriteLock ReentrantReadWriteLock
public ReentrantReadWriteLock()
From source file:org.rhq.enterprise.server.util.concurrent.AlertSerializer.java
public void lock(int alertDefinitionId) { String msg = "tid= " + Thread.currentThread().getId() + ": alertDefinitionId=" + alertDefinitionId; boolean debug = this.log.isDebugEnabled(); ReentrantReadWriteLock lock = null; logDebug(debug, msg, ": about to synchronize"); synchronized (this) { logDebug(debug, msg, ": synchronized"); lock = AlertSerializer.locks.get(alertDefinitionId); if (lock == null) { logDebug(debug, msg, ": creating new lock"); lock = new ReentrantReadWriteLock(); AlertSerializer.locks.put(alertDefinitionId, lock); }/* w w w.jav a 2 s. co m*/ } logDebug(debug, msg, ": acquiring write lock"); long start = System.currentTimeMillis(); lock.writeLock().lock(); long end = System.currentTimeMillis(); long duration = end - start; AlertSerializer.lockTimes.put(alertDefinitionId, Long.valueOf(end)); if (duration < 5000L) { logDebug(debug, msg, ": acquired write lock in millis=" + duration); } else { this.log.info(msg + ": acquired write lock in millis=" + duration); } return; }
From source file:com.espertech.esper.filter.FilterParamIndexRange.java
/** * Constructs the index for matching ranges. * @param attributeName is the name of the event attribute field * @param filterOperator is the type of range * @param eventType is type of events handled *//*from ww w . j av a 2 s.c o m*/ public FilterParamIndexRange(String attributeName, FilterOperator filterOperator, EventType eventType) { super(attributeName, filterOperator, eventType); ranges = new TreeMap<DoubleRange, EventEvaluator>(new DoubleRangeComparator()); rangesRWLock = new ReentrantReadWriteLock(); if (!(filterOperator.isRangeOperator())) { throw new IllegalArgumentException("Invalid filter operator " + filterOperator); } }
From source file:org.apache.servicemix.jbi.cluster.engine.ReconnectTest.java
public void testLoadInOnly() throws Exception { createRoute(Transacted.Jms, true, false, false); final int nbThreads = 10; final int nbExchanges = 10; final ReadWriteLock lock = new ReentrantReadWriteLock(); final CountDownLatch latch = new CountDownLatch(nbThreads); final AtomicInteger id = new AtomicInteger(); lock.writeLock().lock();//from w w w. j a v a 2 s .c om for (int i = 0; i < nbThreads; i++) { new Thread() { public void run() { Channel client = null; try { client = nmr1.createChannel(); lock.readLock().lock(); for (int i = 0; i < nbExchanges; i++) { Exchange exchange = client.createExchange(Pattern.InOnly); exchange.getIn() .setBody(new StringSource("<hello id='" + id.getAndIncrement() + "'/>")); exchange.setTarget(nmr1.getEndpointRegistry() .lookup(ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME))); client.sendSync(exchange); assertEquals(Status.Done, exchange.getStatus()); } } catch (Exception e) { e.printStackTrace(); } finally { lock.readLock().unlock(); latch.countDown(); if (client != null) { client.close(); } } } }.start(); } long t0, t1; cluster2.pause(); t0 = System.currentTimeMillis(); lock.writeLock().unlock(); latch.await(); broker.stop(); cluster2.resume(); Thread.sleep(500); broker = createBroker(false); receiver.assertExchangesReceived(nbThreads * nbExchanges, TIMEOUT); //Thread.sleep(500); //receiver.assertExchangesReceived(nbThreads * nbExchanges, TIMEOUT); t1 = System.currentTimeMillis(); System.err.println("Elapsed time: " + (t1 - t0) + " ms"); System.err.println("Throuput: " + (nbThreads * nbExchanges * 1000 / (t1 - t0)) + " messages/sec"); }
From source file:com.espertech.esper.filter.FilterParamIndexNotRange.java
/** * Constructs the index for matching ranges. * @param attributeName is the name of the event attribute field * @param filterOperator is the type of range * @param eventType is type of events handled *//* ww w . ja va 2 s . co m*/ public FilterParamIndexNotRange(String attributeName, FilterOperator filterOperator, EventType eventType) { super(attributeName, filterOperator, eventType); ranges = new TreeMap<DoubleRange, EventEvaluator>(new DoubleRangeComparator()); evaluators = new HashSet<EventEvaluator>(); rangesRWLock = new ReentrantReadWriteLock(); if (!(filterOperator.isInvertedRangeOperator())) { throw new IllegalArgumentException("Invalid filter operator " + filterOperator); } }
From source file:com.mg.framework.service.DatabaseAuditServiceImpl.java
public DatabaseAuditServiceImpl(boolean isAuditActivated) { this.isAuditActivated = isAuditActivated; entityAuditSetup = new HashMap<String, EntityAuditSetup>(); entityAuditSetupLock = new ReentrantReadWriteLock(); }
From source file:org.apereo.portal.utils.threading.DoubleCheckedCreator.java
public DoubleCheckedCreator() { this(new ReentrantReadWriteLock()); }
From source file:org.xwiki.store.FileDeleteTransactionRunnableTest.java
@Before public void setUp() throws Exception { final File tmpDir = new File(System.getProperty("java.io.tmpdir")); this.storageLocation = new File(tmpDir, "test-storage" + System.identityHashCode(this.getClass())); this.toDelete = this.storageLocation; for (int i = 0; i < FILE_PATH.length; i++) { this.toDelete = new File(this.toDelete, FILE_PATH[i]); }/*from www . j av a2 s . c om*/ this.temp = new File(this.toDelete.getParentFile(), FILE_PATH[FILE_PATH.length - 1] + "~tmp"); this.toDelete.getParentFile().mkdirs(); IOUtils.write("Delete me!", new FileOutputStream(this.toDelete)); IOUtils.write("HAHA I am here to trip you up!", new FileOutputStream(this.temp)); this.lock = new ReentrantReadWriteLock(); this.runnable = new FileDeleteTransactionRunnable(this.toDelete, this.temp, this.lock); }
From source file:com.openteach.diamond.repository.client.cache.HyBridLRUCache.java
/** * //from w ww.j a v a 2 s .c o m * @param maxEntriesInMemory ? * @param maxEntries ? (maxEntries = maxEntriesInMemory + maxEntriesInFile) * @param fileName local file name for file cache */ public HyBridLRUCache(int maxEntriesInMemory, int maxEntries, String fileName) { /** * */ memoryCache = new MemoryLRUCache<K, V>(maxEntriesInMemory); /** * File */ fileCache = new FileLRUCache<K, V>(maxEntries, fileName); memoryCache.register(new ItemEliminateListener<K, V>() { @Override public void onEliminated(K key, V v) { try { _f_rw_lock_.writeLock().lock(); fileCache.put(key, v); } finally { _f_rw_lock_.writeLock().unlock(); } } }); fileCache.register(new ItemEliminateListener<K, V>() { @Override public void onEliminated(K key, V v) { logger.warn(String.format("Eliminated one from file (local cache), key:%s", key.toString())); } }); _m_rw_lock_ = new ReentrantReadWriteLock(); _f_rw_lock_ = new ReentrantReadWriteLock(); }
From source file:org.pascani.dsl.lib.util.log4j2.PascaniAppender.java
private PascaniAppender(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions) throws Exception { super(name, filter, layout, ignoreExceptions); this.readLock = new ReentrantReadWriteLock().readLock(); this.producer = new RabbitMQProducer(PascaniRuntime.getEnvironment().get("logs_exchange"), this.getClass().getCanonicalName()); }
From source file:org.eclipse.nebula.widgets.nattable.selection.SelectionModel.java
public SelectionModel(SelectionLayer selectionLayer, boolean multipleSelectionAllowed) { this.selectionLayer = selectionLayer; this.multipleSelectionAllowed = multipleSelectionAllowed; selections = new LinkedList<Rectangle>(); selectionsLock = new ReentrantReadWriteLock(); }