@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); } }