Class LockHelper


  • public class LockHelper
    extends java.lang.Object
    Helper to make trying for read-write locks simpler
    Since:
    4.1.7
    Author:
    Derek Hulley
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LockHelper.LockTryException
      Exception generated when a lock try is unsuccessful
    • Constructor Summary

      Constructors 
      Constructor Description
      LockHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void tryLock​(java.util.concurrent.locks.Lock lock, long timeoutMs, java.lang.String useCase)
      Try to get a lock in the given number of milliseconds or get an exception
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LockHelper

        public LockHelper()
    • Method Detail

      • tryLock

        public static void tryLock​(java.util.concurrent.locks.Lock lock,
                                   long timeoutMs,
                                   java.lang.String useCase)
                            throws LockHelper.LockTryException
        Try to get a lock in the given number of milliseconds or get an exception
        Parameters:
        lock - the lock to try
        timeoutMs - the number of milliseconds to try
        useCase - String value which specifies description of use case when lock is needed
        Throws:
        LockHelper.LockTryException - the exception if the time is exceeded or the thread is interrupted