Neron Neron - 1 year ago 116
Java Question

Coherence lock-unlock usage

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();
Thread a=new Thread(test);

public static class Trt implements Runnable{

NamedCache cache=null;

public void run() {



public void lock(){
cache= CacheFactory.getCache(Globals.REGISTRY_CACHE_NAME);




So the result is:


The result that I am expecting is:


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
in the end?



Answer Source

From Oracle Coherence Developer's Guide:

When a lock is in place, it is the responsibility of the caller (either in the same thread or the same cluster node, depending on the lease-granularity configuration) to release the lock.

By default Coherence uses thread ownership granularity, so that is probably the reason lock is not being released.

A value of thread means that locks are held by a thread that obtained them and can only be released by that thread. A value of member means that locks are held by a cluster node and any thread running on the cluster node that obtained the lock can release it.

See and for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download