0

I am using a rest endpoint to start a java process using executeWithLock which takes in a LockingTaskExecutor.TaskWithResult(call method of TaskWithResult calls the java process/method). This works fine and it allows only single execution of java process at any point of time and I can get the status of execution from TaskResult. In some cases the java process is long running and the rest call stalls as the process is still getting executed,

I tried to make my java process @Async but then the lock is released irrespective of the execution of the async process and unlock before completion of async process.

Is there any way to get the lock status by name and so that in case of no lock I can call executeWithLock in a separate thread and return immediately? if it is already locked I will skip calling executeWithLock and return immediately.

or is there any other solution for this kind of scenario?

1 Answers1

0

If you call executeWithLock, and the lock is being held by another process, the call will return immidiatelly.

Lukas
  • 13,606
  • 9
  • 31
  • 40
  • Yes, I could see it returns immediately if another process is running. But if it doesnt, it will execute the process and it will block. I want to know if this can be made unblocking?. if there was an API to check lock status, I could call executeWithLock in a different thread. – user2043662 Sep 09 '21 at 00:35
  • I see. There is no such API. But you can change the order - start the new thread first and lock in the new thread. If the lock is held by another process, the thread will be released at once, of not the lock will be held until the task is finished – Lukas Sep 11 '21 at 05:51