1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| @Test public void redissonLockTest() { RLock rLock = redissonClient.getLock("MYLOCK1"); try { boolean isrLock = rLock.tryLock(5, TimeUnit.SECONDS); System.out.println("sleep11++++++" + isrLock); if (isrLock) { Thread.sleep(15000); System.out.println("lock is still here but i unlock it"); rLock.unlock(); Thread.sleep(15000); System.out.println("=====sleep11 finish!!!"); }
} catch (Exception e) { e.printStackTrace(); rLock.unlock(); } }
@Test public void redissonLockTest2() { RLock rLock = redissonClient.getLock("MYLOCK1"); try { boolean isrLock = rLock.tryLock(5, TimeUnit.SECONDS); System.out.println("sleep22++++++" + isrLock); while (!isrLock) { isrLock = rLock.tryLock(10, TimeUnit.SECONDS); if (isrLock) { System.out.println("i have lock!"); Thread.sleep(5000); System.out.println("=====sleep22 finish!!!"); } else { System.out.println("i have no lock"); } } } catch (Exception e) { e.printStackTrace(); rLock.unlock(); } }
|