我有連貫性鎖定 - 開鎖機構這樣的試驗樣品:連貫鎖定解鎖使用
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
?
感謝
阿里
它打印真實但不打印錯誤?並且在打印false之前退出程序? – alexey28
我認爲這應該是真的。或者我錯誤地認爲:) – Neron