Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

10
LINES

< > TinyBrain | #1007379 - lockOrFail - try to acquire a Lock; fail after timeout

JavaX fragment (include)

static void lockOrFail(Lock lock, long timeout) ctex {
  if (!lock.tryLock(timeout, TimeUnit.MILLISECONDS)) {
    S s = "Couldn't acquire lock after " + timeout + " ms.";
    if (lock instanceof ReentrantLock) {
      ReentrantLock l = cast lock;
      s += " Hold count: " + l.getHoldCount() + ", owner: " + call(l, "getOwner");
    }
    fail(s);
  }
}

download  show line numbers  debug dex   

Travelled to 1 computer(s): tvejysmllsmz

No comments. add comment

Snippet ID: #1007379
Snippet name: lockOrFail - try to acquire a Lock; fail after timeout
Eternal ID of this version: #1007379/7
Text MD5: 1fd57c56f9fb7432d954cc22b0a2217a
Author: stefan
Category: javax / concurrency
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-03-18 17:32:38
Source code size: 363 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 23 / 3
Version history: 6 change(s)
Referenced in: [show]