{"action":"created","issue":{"url":"https://api.github.com/repos/hazelcast/hazelcast/issues/6742","labels_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/6742/labels{/name}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/6742/comments","events_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/6742/events","html_url":"https://github.com/hazelcast/hazelcast/issues/6742","id":116978697,"number":6742,"title":"Acquiring lock on a key in Imap for multithreading set up  ","user":{"login":"shyam4u","id":14305169,"avatar_url":"https://avatars.githubusercontent.com/u/14305169?v=3","gravatar_id":"","url":"https://api.github.com/users/shyam4u","html_url":"https://github.com/shyam4u","followers_url":"https://api.github.com/users/shyam4u/followers","following_url":"https://api.github.com/users/shyam4u/following{/other_user}","gists_url":"https://api.github.com/users/shyam4u/gists{/gist_id}","starred_url":"https://api.github.com/users/shyam4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shyam4u/subscriptions","organizations_url":"https://api.github.com/users/shyam4u/orgs","repos_url":"https://api.github.com/users/shyam4u/repos","events_url":"https://api.github.com/users/shyam4u/events{/privacy}","received_events_url":"https://api.github.com/users/shyam4u/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-11-15T07:23:17Z","updated_at":"2015-11-15T20:39:10Z","closed_at":null,"body":"I have a Imap on which I plan to acquire a lock against a key in the Imap .There would be multiple threads trying to acquire the lock and I have 2 conditions to satisfy .\r\n\r\n1.I have the luxury to skip the operation needed to be performed after acquiring the lock -if the wait time for acquiring the lock is more than 20 milliseconds .\r\n2.After completion of my lock I can unlock the key and I also plan to have a lease time for which the lock can be acquired by a thread .\r\n\r\nBelow is my code block \r\n1. Here I check if a lock is available and if I acquired the lock ,I again lock the key for 40 milliseconds(lease time) .The lock is released after the operation is done or after lease time if over .\r\n2. If another thread comes to acquire the lock ,I t would wait for 20 secs or it should skip the operation .\r\nMy questions here wrf to the code below \r\nFor a thread who acquired the lock am i locking twice ? \r\nWhat will happen if I triggger the below statement in sequence for a thread who acquired the lock.\r\n\r\n boolean acquiredLock = getImap().tryLock(key, 20, TimeUnit.Milliseconds);\r\n            if (acquiredLock) {\r\n                getImap().lock(key, 40, TimeUnit.Milliseconds);\r\n                LOG.debug(\"locked for key  and by thread>>>>>>\" + Thread.currentThread().getName());\r\n            }"},"comment":{"url":"https://api.github.com/repos/hazelcast/hazelcast/issues/comments/156851536","html_url":"https://github.com/hazelcast/hazelcast/issues/6742#issuecomment-156851536","issue_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/6742","id":156851536,"user":{"login":"jerrinot","id":158619,"avatar_url":"https://avatars.githubusercontent.com/u/158619?v=3","gravatar_id":"","url":"https://api.github.com/users/jerrinot","html_url":"https://github.com/jerrinot","followers_url":"https://api.github.com/users/jerrinot/followers","following_url":"https://api.github.com/users/jerrinot/following{/other_user}","gists_url":"https://api.github.com/users/jerrinot/gists{/gist_id}","starred_url":"https://api.github.com/users/jerrinot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerrinot/subscriptions","organizations_url":"https://api.github.com/users/jerrinot/orgs","repos_url":"https://api.github.com/users/jerrinot/repos","events_url":"https://api.github.com/users/jerrinot/events{/privacy}","received_events_url":"https://api.github.com/users/jerrinot/received_events","type":"User","site_admin":false},"created_at":"2015-11-15T20:39:10Z","updated_at":"2015-11-15T20:39:10Z","body":"I believe so. either T1 or T2 should acquire the lock. That's the behaviour I'd expect."}}