In Hazelcast, is it possible to use clustered locks that do _not_ care about the local thread that performs the lock/unlock operations?

吃可爱长大的小学妹 提交于 2019-12-05 14:19:50

The Semaphore is your friend because it doesn't have a concept of ownership. It uses permits that can be acquired; thread x can acquire permit 1, but thread y can release permit 1. If you initialize the semaphore with a single permit, you will get your mutual exclusion.

ISemaphore s = hazelcastInstance.getSemaphore("foo");
s.init(1);
s.acquire(); 

And in another thread you can release this permit by:

ISemaphore s = hazelcastInstance.getSemaphore("foo");
s.release(); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!