use of java.util.concurrent.locks.ReadWriteLock in project languagetool by languagetool-org.
the class AbstractLanguageConcurrencyTest method testSpellCheckerFailure.
@Ignore("too slow to run every time")
@Test
public void testSpellCheckerFailure() throws Exception {
String sampleText = createSampleText();
Language language = createLanguage();
int threadCount = Runtime.getRuntime().availableProcessors() * 10;
int testRuns = 100;
ReadWriteLock testWaitLock = new ReentrantReadWriteLock();
Lock testWriteLock = testWaitLock.writeLock();
testWriteLock.lock();
failedTests = 0;
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < threadCount; i++) {
Thread t = new Thread(new TestRunner(testWaitLock, language, testRuns, sampleText));
t.start();
threads.add(t);
}
// Release the lock and allow all TestRunner threads to do their work.
testWriteLock.unlock();
for (Thread t : threads) {
t.join();
}
Assert.assertEquals(0, failedTests);
}
use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.
the class OPartitionedLockManager method releaseSharedLock.
public void releaseSharedLock(final long value) {
final int hashCode = longHashCode(value);
final int index = index(hashCode);
if (useSpinLock) {
final OReadersWriterSpinLock spinLock = spinLocks[index];
spinLock.releaseReadLock();
return;
}
final ReadWriteLock rwLock = locks[index];
final Lock lock = rwLock.readLock();
lock.unlock();
}
use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.
the class OPartitionedLockManager method tryAcquireSharedLock.
public boolean tryAcquireSharedLock(T value, long timeout) throws InterruptedException {
if (useSpinLock)
throw new IllegalStateException("Spin lock does not support try lock mode");
final int index;
if (value == null)
index = 0;
else
index = index(value.hashCode());
final ReadWriteLock rwLock = locks[index];
final Lock lock = rwLock.readLock();
return lock.tryLock(timeout, TimeUnit.MILLISECONDS);
}
use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.
the class OPartitionedLockManager method releaseExclusiveLock.
public void releaseExclusiveLock(final int value) {
final int index = index(value);
if (useSpinLock) {
OReadersWriterSpinLock spinLock = spinLocks[index];
spinLock.releaseWriteLock();
return;
}
final ReadWriteLock rwLock = locks[index];
rwLock.writeLock().unlock();
}
use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.
the class OPartitionedLockManager method acquireSharedLock.
@Override
public Lock acquireSharedLock(final T value) {
final int index;
if (value == null)
index = 0;
else
index = index(value.hashCode());
if (useSpinLock) {
OReadersWriterSpinLock spinLock = spinLocks[index];
spinLock.acquireReadLock();
return new SpinLockWrapper(true, spinLock);
}
final ReadWriteLock rwLock = locks[index];
final Lock lock = rwLock.readLock();
lock.lock();
return lock;
}
Aggregations