Java Code Examples for org.redisson.api.RSemaphore#acquire()
The following examples show how to use
org.redisson.api.RSemaphore#acquire() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonLockHeavyTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void lockUnlockRLock() throws Exception { for (int i = 0; i < threads; i++) { Runnable worker = new Runnable() { @Override public void run() { for (int j = 0; j < loops; j++) { RLock lock = redisson.getLock("RLOCK_" + j); lock.lock(); try { RBucket<String> bucket = redisson.getBucket("RBUCKET_" + j); bucket.set("TEST", 30, TimeUnit.SECONDS); RSemaphore semaphore = redisson.getSemaphore("SEMAPHORE_" + j); semaphore.release(); try { semaphore.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } } finally { lock.unlock(); } } } }; executor.execute(worker); } executor.shutdown(); executor.awaitTermination(threads * loops, TimeUnit.SECONDS); }
Example 2
Source File: RedissonSemaphoreTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAcquireWithoutSetPermits() throws InterruptedException { RSemaphore s = redisson.getSemaphore("test"); s.release(); s.release(); s.acquire(2); }
Example 3
Source File: RedissonSemaphoreTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReducePermits() throws InterruptedException { RSemaphore s = redisson.getSemaphore("test"); s.trySetPermits(10); s.acquire(10); s.reducePermits(5); assertThat(s.availablePermits()).isEqualTo(-5); s.release(10); assertThat(s.availablePermits()).isEqualTo(5); s.acquire(5); assertThat(s.availablePermits()).isEqualTo(0); }
Example 4
Source File: RedissonSemaphoreTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testDrainPermits() throws InterruptedException { RSemaphore s = redisson.getSemaphore("test"); s.trySetPermits(10); s.acquire(3); assertThat(s.drainPermits()).isEqualTo(7); assertThat(s.availablePermits()).isEqualTo(0); }
Example 5
Source File: RedissonSemaphoreTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReleaseAcquire() throws InterruptedException { RSemaphore s = redisson.getSemaphore("test"); s.trySetPermits(10); s.acquire(); assertThat(s.availablePermits()).isEqualTo(9); s.release(); assertThat(s.availablePermits()).isEqualTo(10); s.acquire(5); assertThat(s.availablePermits()).isEqualTo(5); s.release(5); assertThat(s.availablePermits()).isEqualTo(10); }