@Override public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo) throws NotAuthorizedException { LockHolder r = annoFactory.createLockHolder(this, name, timeout, lockInfo); if (children != null) { CommonResource cr = annoFactory.instantiate(r, parent); children.add(cr); } return new LockToken(r.getId().toString(), lockInfo, timeout); }
@Override public void run() { String threadName = Thread.currentThread().getName(); try { int count = 0; while (count < 100) { Thread.sleep(1000); synchronized (lockHolder) { if (lockHolder.getHolder() == number) { System.out.println("Thread: [".concat(threadName).concat("]...")); lockHolder.setHolder((number + 1) % threadSize); } else { lockHolder.wait(100); } } count++; } } catch (InterruptedException e) { throw new RuntimeException(e); } }