I created a distributed lock class that I designed to be used like this:
myLock.lock();
doSomething();
myLock.unlock();
In my current implementation, lock() blocks until the lock is acquired. But I am running into some deadlock issues with this implementation. So I'd like to rewrite it to be asynchronous, but I have no idea how to do that in java.
Something like this would work I think:
myLock.lock(myCallbackFunction);
private void myCallbackFunction(boolean result){
if(result){
doSomething();
mylock.Unlock();
}
}
Is there a way to do this in java?
EDIT (More detail): The reasons why the synchronous implementation is deadlocking are complicated and not relevant. The distributed lock is acquiring mutual exclusion of a resource across a network with multiple systems. Really the only thing I'm looking for is how to write a method that accepts a callback function.