I have a test sample about coherence lock-unlock mechanism like this:
public class Test {
public static void main(String[] args) throws InterruptedException, IOException, IllegalArgumentException, IllegalAccessException {
Trt test=new Trt();
test.lock();
Thread a=new Thread(test);
a.start();
}
public static class Trt implements Runnable{
NamedCache cache=null;
@Override
public void run() {
System.out.println(cache.unlock("asd"));
}
public void lock(){
cache= CacheFactory.getCache(Globals.REGISTRY_CACHE_NAME);
System.out.println(cache.lock("asd"));
}
}
}
So the result is:
true
false
The result that I am expecting is:
true
true
But the case is, I have only one item ‘test’, I am all using it and it has only one cache instance in it. So the owner of the cache is that cache instance.
Why is it not able to close it and returns false in the end?
Thanks
Ali
From Oracle Coherence Developer’s Guide:
By default Coherence uses thread ownership granularity, so that is probably the reason lock is not being released.
See http://docs.oracle.com/cd/E24290_01/coh.371/e22837/api_transactionslocks.htm#BEIIEEBB and http://docs.oracle.com/cd/E24290_01/coh.371/e22837/appendix_operational.htm#BAGJBCEF for more details.