本文整理了Java中org.apache.ignite.Ignite.reentrantLock()
方法的一些代码示例,展示了Ignite.reentrantLock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.reentrantLock()
方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:reentrantLock
[英]Gets or creates reentrant lock. If reentrant lock is not found in cache and create flag is true, it is created using provided name.
[中]获取或创建可重入锁。若在缓存中找不到可重入锁且create标志为true,则使用提供的名称创建该锁。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Nullable @Override public IgniteLock reentrantLock(String name,
boolean failoverSafe,
boolean fair,
boolean create)
{
checkIgnite();
return g.reentrantLock(name, failoverSafe, fair, create);
}
代码示例来源:origin: apache/ignite
/**
* Provides {@link org.apache.ignite.IgniteLock} for specified cache name and key.
*
* @param name cache name
* @param key key
* @return {@link org.apache.ignite.IgniteLock}
*/
IgniteLock getSyncLock(String name, Object key) {
int hash = Objects.hash(name, key);
final int idx = hash % getLocksCount();
return locks.computeIfAbsent(idx, i -> ignite.reentrantLock(SPRING_LOCK_NAME_PREFIX + idx, true, false, true));
}
}
代码示例来源:origin: apache/ignite
@Override public void applyx(Ignite ignite) {
IgniteLock r = ignite.reentrantLock(TEST_REENTRANT_LOCK_NAME, true, false, true);
for (int i = 0; i < operationsPerTx; i++) {
r.isLocked();
long cnt = reads.incrementAndGet();
if (cnt % READ_LOG_MOD == 0)
info("Performed " + cnt + " reads.");
}
}
};
代码示例来源:origin: apache/ignite
@Override public Void apply(Ignite ignite) {
final IgniteLock l = ignite.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false);
final AtomicBoolean done = new AtomicBoolean(false);
GridTestUtils.runAsync(new Callable<Void>() {
@Override public Void call() throws Exception {
try{
l.lock();
}
finally {
done.set(true);
}
return null;
}
}, "lock-thread");
// Wait until l.lock() has been called.
while(!l.hasQueuedThreads() && !done.get()){
// No-op.
}
return null;
}
});
代码示例来源:origin: apache/ignite
@Override public void applyx(Ignite ignite) {
IgniteLock r = ignite.reentrantLock(TEST_REENTRANT_LOCK_NAME, true, false, true);
for (int i = 0; i < operationsPerTx; i++) {
if ((i % 2) == 0)
r.lock();
else
r.unlock();
long cnt = writes.incrementAndGet();
if (cnt % WRITE_LOG_MOD == 0)
info("Performed " + cnt + " writes.");
}
}
};
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testLockVolatility() throws Exception {
Ignite ignite = startGrids(4);
ignite.active(true);
IgniteLock lock = ignite.reentrantLock("test", false, true, true);
assert lock != null;
stopAllGrids();
ignite = startGrids(4);
ignite.active(true);
lock = ignite.reentrantLock("test", false, true, false);
assert lock == null;
}
代码示例来源:origin: apache/ignite
@Override public Object apply(Ignite ignite) {
final IgniteLock l = ignite.reentrantLock("lock", true, fair, true);
l.lock();
assertTrue(l.isHeldByCurrentThread());
l.unlock();
assertFalse(l.isHeldByCurrentThread());
// Signal the server to go down.
ignite.semaphore("sync", 0, true, true).release();
boolean isExceptionThrown = false;
try {
// Wait for the server to go down.
Thread.sleep(1000);
l.lock();
fail("Exception must be thrown.");
}
catch (InterruptedException ignored) {
fail("Interrupted exception not expected here.");
}
catch (IgniteException ignored) {
isExceptionThrown = true;
}
finally {
assertTrue(isExceptionThrown);
assertFalse(l.isHeldByCurrentThread());
}
return null;
}
}, client);
代码示例来源:origin: apache/ignite
IgniteLock l = ignite.reentrantLock("lock", true, true, true);
代码示例来源:origin: apache/ignite
final IgniteLock lock0 = g0.reentrantLock("lock", false, fair, false);
代码示例来源:origin: apache/ignite
IgniteLock srvLock = server.reentrantLock("lock", true, fair, true);
代码示例来源:origin: apache/ignite
IgniteLock l = g.reentrantLock(STRUCTURE_NAME, failoverSafe, fair, false);
代码示例来源:origin: apache/ignite
IgniteLock clientLock = client.reentrantLock("lock1", true, fair, true);
final IgniteLock srvLock = srv.reentrantLock("lock1", true, fair, true);
代码示例来源:origin: apache/ignite
IgniteLock lock = ignite.reentrantLock("lock", true, true, true);
代码示例来源:origin: org.apache.ignite/ignite-spring
/** {@inheritDoc} */
@Nullable @Override public IgniteLock reentrantLock(String name,
boolean failoverSafe,
boolean fair,
boolean create)
{
checkIgnite();
return g.reentrantLock(name, failoverSafe, fair, create);
}
代码示例来源:origin: org.apache.ignite/ignite-spring
/**
* Provides {@link org.apache.ignite.IgniteLock} for specified cache name and key.
*
* @param name cache name
* @param key key
* @return {@link org.apache.ignite.IgniteLock}
*/
IgniteLock getSyncLock(String name, Object key) {
int hash = Objects.hash(name, key);
final int idx = hash % getLocksCount();
return locks.computeIfAbsent(idx, i -> ignite.reentrantLock(SPRING_LOCK_NAME_PREFIX + idx, true, false, true));
}
}
内容来源于网络,如有侵权,请联系作者删除!