Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 72EDD200B85 for ; Thu, 1 Sep 2016 01:59:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7137F160AB4; Wed, 31 Aug 2016 23:59:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C1F87160AC4 for ; Thu, 1 Sep 2016 01:59:21 +0200 (CEST) Received: (qmail 58475 invoked by uid 500); 31 Aug 2016 23:59:20 -0000 Mailing-List: contact dev-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list dev@curator.apache.org Received: (qmail 58173 invoked by uid 99); 31 Aug 2016 23:59:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Aug 2016 23:59:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 891D32C1B7F for ; Wed, 31 Aug 2016 23:59:20 +0000 (UTC) Date: Wed, 31 Aug 2016 23:59:20 +0000 (UTC) From: "Meni Hillel (JIRA)" To: dev@curator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CURATOR-347) Shared read/write lock acquired by one thread cannot be released by another MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 31 Aug 2016 23:59:22 -0000 [ https://issues.apache.org/jira/browse/CURATOR-347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15453786#comment-15453786 ] Meni Hillel commented on CURATOR-347: ------------------------------------- Also should add, this works perfectly fine with InterProcessSemaphoreMutex. Question is why are these two behave different...? I need non-reentrant, read/write lock which are thread agnostic. > Shared read/write lock acquired by one thread cannot be released by another > --------------------------------------------------------------------------- > > Key: CURATOR-347 > URL: https://issues.apache.org/jira/browse/CURATOR-347 > Project: Apache Curator > Issue Type: Bug > Components: Recipes > Affects Versions: 3.2.0 > Reporter: Meni Hillel > Fix For: awaiting-response > > > Consider the following: lock is being acquired by main thread but released by another thread. This throws an exception: > java.lang.IllegalMonitorStateException: You do not own the lock: /locks/abc > at org.apache.curator.framework.recipes.locks.InterProcessMutex.release(InterProcessMutex.java:140) > Are locks thread specific? That wouldn't make sense. How else can I achieve this? Also would be nice to have a non-reentrant read/write shared lock. > public static void main(String[] args) throws Exception { > final CuratorFramework client = CuratorFrameworkFactory.builder() > .connectString(ApplicationProperties.getConfig().getMessagebusSyncServers()).sessionTimeoutMs(5000) > .connectionTimeoutMs(3000).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); > client.start(); > InterProcessReadWriteLock lock = new InterProcessReadWriteLock(client, "/locks/abc"); > lock.writeLock().acquire(); > Thread r = new Thread() { > @Override > public void run() { > try { > InterProcessReadWriteLock lock = new InterProcessReadWriteLock(client, "/locks/abc"); > lock.writeLock().release(); > } catch (Exception e) { > e.printStackTrace(); > } > } > }; > r.start(); > r.join(); > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)