Class FileLockExecutor

  • All Implemented Interfaces:
    LockExecutor, Executor

    public class FileLockExecutor
    extends Object
    implements LockExecutor
    An executor that uses file locking to ensure runnable instances are executed sequentially.
    Since:
    3.5.0
    • Constructor Detail

      • FileLockExecutor

        public FileLockExecutor​(File file)
        Creates an executor locking on the specified file.
        Parameters:
        file - the file to lock to ensure non concurrent executions.
    • Method Detail

      • execute

        public <V> V execute​(Callable<V> command)
                      throws Exception
        Description copied from interface: LockExecutor
        Executes the given task and returns its computed result, with the guarantee no other task for the same lock can run concurrently.

        The task is expected to be very lightweight and short-running, so that it does't block for too long other concurrent requests.

        Specified by:
        execute in interface LockExecutor
        Type Parameters:
        V - the result type of method call
        Parameters:
        command - the runnable task
        Returns:
        the computed result
        Throws:
        Exception - if unable to compute a result. The exception is a CompletionException if the task is either interrupted or the timeout to acquire the lock expires.