java - 一致性锁定解锁用法

标签 java caching locking oracle-coherence

我有一个关于一致性锁定-解锁机制的测试示例,如下所示:

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"));

        }

    }
}

所以结果是:

true
false

我期望的结果是:

true
true

但情况是,我只有一项“测试”,我都在使用它,并且它只有一个缓存实例。所以缓存的所有者就是该缓存实例。

为什么无法关闭,最后返回false

谢谢

阿里

最佳答案

来自 Oracle Coherence 开发人员指南:

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.

默认情况下,Coherence 使用线程所有权粒度,因此这可能是锁未释放的原因。

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.

参见http://docs.oracle.com/cd/E24290_01/coh.371/e22837/api_transactionslocks.htm#BEIIEEBBhttp://docs.oracle.com/cd/E24290_01/coh.371/e22837/appendix_operational.htm#BAGJBCEF了解更多详情。

关于java - 一致性锁定解锁用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11009430/

相关文章:

java - t :commandSortHeader not being styled

java - 在 Java 中获取屏幕大小

caching - 如何设置cdn?

jquery - JCrop 缓存图像

c# - 如何在构造函数中正确实例化静态 HttpClient

c++ - 关于哪些线程空闲的线程之间进行协调的最有效方法是什么?

java - Java是如何实现锁的

java - 如果两个或多个对象存储在同一索引中,LinkedHashMap 如何保持顺序

java - 从 R.ID 接收微调器给出 NullPointerException

Django Nginx 浏览器缓存配置