Java 类com.google.common.util.concurrent.CycleDetectingLockFactory.Policies 实例源码

项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_acquiringMultipleLocksWithSameRank() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantLock(OtherOrder.FIRST);
  Lock lockB = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();

  lockA.lock();
  try {
    lockB.lock();
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {
  }

  lockA.unlock();
  lockB.lock();
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories_policyExecution() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockD -> lockA
  lockD.lock();
  lockA.lock();
  lockA.unlock();
  lockD.unlock();

  // lockA -> lockD should warn but otherwise succeed because lockD was
  // created by a factory with the WARN policy.
  lockA.lock();
  lockD.lock();
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_acquiringMultipleLocksWithSameRank() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantLock(OtherOrder.FIRST);
  Lock lockB = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();

  lockA.lock();
  try {
    lockB.lock();
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {
  }

  lockA.unlock();
  lockB.lock();
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories_policyExecution() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockD -> lockA
  lockD.lock();
  lockA.lock();
  lockA.unlock();
  lockD.unlock();

  // lockA -> lockD should warn but otherwise succeed because lockD was
  // created by a factory with the WARN policy.
  lockA.lock();
  lockD.lock();
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_acquiringMultipleLocksWithSameRank() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantLock(OtherOrder.FIRST);
  Lock lockB = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();

  lockA.lock();
  try {
    lockB.lock();
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {
  }

  lockA.unlock();
  lockB.lock();
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories_policyExecution() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockD -> lockA
  lockD.lock();
  lockA.lock();
  lockA.unlock();
  lockD.unlock();

  // lockA -> lockD should warn but otherwise succeed because lockD was
  // created by a factory with the WARN policy.
  lockA.lock();
  lockD.lock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW).newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_acquiringMultipleLocksWithSameRank() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantLock(OtherOrder.FIRST);
  Lock lockB = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();

  lockA.lock();
  try {
    lockB.lock();
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {
  }

  lockA.unlock();
  lockB.lock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory = CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW).newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_acquiringMultipleLocksWithSameRank() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantLock(OtherOrder.FIRST);
  Lock lockB = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();

  lockA.lock();
  try {
    lockB.lock();
    fail("Expected IllegalStateException");
  } catch (IllegalStateException expected) {
  }

  lockA.unlock();
  lockB.lock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory = CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  CycleDetectingLockFactory factory =
      CycleDetectingLockFactory.newInstance(Policies.THROW);
  lockA = factory.newReentrantLock("LockA");
  lockB = factory.newReentrantLock("LockB");
  lockC = factory.newReentrantLock("LockC");
  ReentrantReadWriteLock readWriteLockA =
      factory.newReentrantReadWriteLock("ReadWriteA");
  ReentrantReadWriteLock readWriteLockB =
      factory.newReentrantReadWriteLock("ReadWriteB");
  ReentrantReadWriteLock readWriteLockC =
      factory.newReentrantReadWriteLock("ReadWriteC");
  readLockA = readWriteLockA.readLock();
  readLockB = readWriteLockB.readLock();
  readLockC = readWriteLockC.readLock();
  writeLockA = readWriteLockA.writeLock();
  writeLockB = readWriteLockB.writeLock();
  writeLockC = readWriteLockC.writeLock();

  CycleDetectingLockFactory.WithExplicitOrdering<MyOrder> factory2 =
      newInstanceWithExplicitOrdering(MyOrder.class, Policies.THROW);
  lock1 = factory2.newReentrantLock(MyOrder.FIRST);
  lock2 = factory2.newReentrantLock(MyOrder.SECOND);
  lock3 = factory2.newReentrantLock(MyOrder.THIRD);

  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory3 =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  lock01 = factory3.newReentrantLock(OtherOrder.FIRST);
  lock02 = factory3.newReentrantLock(OtherOrder.SECOND);
  lock03 = factory3.newReentrantLock(OtherOrder.THIRD);
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_reentrantAcquisition() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();
  Lock lockB = factory.newReentrantLock(OtherOrder.SECOND);

  lockA.lock();
  lockA.lock();
  lockB.lock();
  lockB.lock();
  lockA.unlock();
  lockA.unlock();
  lockB.unlock();
  lockB.unlock();
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  CycleDetectingLockFactory factory =
      CycleDetectingLockFactory.newInstance(Policies.THROW);
  lockA = factory.newReentrantLock("LockA");
  lockB = factory.newReentrantLock("LockB");
  lockC = factory.newReentrantLock("LockC");
  ReentrantReadWriteLock readWriteLockA =
      factory.newReentrantReadWriteLock("ReadWriteA");
  ReentrantReadWriteLock readWriteLockB =
      factory.newReentrantReadWriteLock("ReadWriteB");
  ReentrantReadWriteLock readWriteLockC =
      factory.newReentrantReadWriteLock("ReadWriteC");
  readLockA = readWriteLockA.readLock();
  readLockB = readWriteLockB.readLock();
  readLockC = readWriteLockC.readLock();
  writeLockA = readWriteLockA.writeLock();
  writeLockB = readWriteLockB.writeLock();
  writeLockC = readWriteLockC.writeLock();

  CycleDetectingLockFactory.WithExplicitOrdering<MyOrder> factory2 =
      newInstanceWithExplicitOrdering(MyOrder.class, Policies.THROW);
  lock1 = factory2.newReentrantLock(MyOrder.FIRST);
  lock2 = factory2.newReentrantLock(MyOrder.SECOND);
  lock3 = factory2.newReentrantLock(MyOrder.THIRD);

  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory3 =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  lock01 = factory3.newReentrantLock(OtherOrder.FIRST);
  lock02 = factory3.newReentrantLock(OtherOrder.SECOND);
  lock03 = factory3.newReentrantLock(OtherOrder.THIRD);
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_reentrantAcquisition() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();
  Lock lockB = factory.newReentrantLock(OtherOrder.SECOND);

  lockA.lock();
  lockA.lock();
  lockB.lock();
  lockB.lock();
  lockA.unlock();
  lockA.unlock();
  lockB.unlock();
  lockB.unlock();
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  CycleDetectingLockFactory factory =
      CycleDetectingLockFactory.newInstance(Policies.THROW);
  lockA = factory.newReentrantLock("LockA");
  lockB = factory.newReentrantLock("LockB");
  lockC = factory.newReentrantLock("LockC");
  ReentrantReadWriteLock readWriteLockA =
      factory.newReentrantReadWriteLock("ReadWriteA");
  ReentrantReadWriteLock readWriteLockB =
      factory.newReentrantReadWriteLock("ReadWriteB");
  ReentrantReadWriteLock readWriteLockC =
      factory.newReentrantReadWriteLock("ReadWriteC");
  readLockA = readWriteLockA.readLock();
  readLockB = readWriteLockB.readLock();
  readLockC = readWriteLockC.readLock();
  writeLockA = readWriteLockA.writeLock();
  writeLockB = readWriteLockB.writeLock();
  writeLockC = readWriteLockC.writeLock();

  CycleDetectingLockFactory.WithExplicitOrdering<MyOrder> factory2 =
      newInstanceWithExplicitOrdering(MyOrder.class, Policies.THROW);
  lock1 = factory2.newReentrantLock(MyOrder.FIRST);
  lock2 = factory2.newReentrantLock(MyOrder.SECOND);
  lock3 = factory2.newReentrantLock(MyOrder.THIRD);

  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory3 =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  lock01 = factory3.newReentrantLock(OtherOrder.FIRST);
  lock02 = factory3.newReentrantLock(OtherOrder.SECOND);
  lock03 = factory3.newReentrantLock(OtherOrder.THIRD);
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_reentrantAcquisition() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();
  Lock lockB = factory.newReentrantLock(OtherOrder.SECOND);

  lockA.lock();
  lockA.lock();
  lockB.lock();
  lockB.lock();
  lockA.unlock();
  lockA.unlock();
  lockB.unlock();
  lockB.unlock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  CycleDetectingLockFactory factory = CycleDetectingLockFactory.newInstance(Policies.THROW);
  lockA = factory.newReentrantLock("LockA");
  lockB = factory.newReentrantLock("LockB");
  lockC = factory.newReentrantLock("LockC");
  ReentrantReadWriteLock readWriteLockA = factory.newReentrantReadWriteLock("ReadWriteA");
  ReentrantReadWriteLock readWriteLockB = factory.newReentrantReadWriteLock("ReadWriteB");
  ReentrantReadWriteLock readWriteLockC = factory.newReentrantReadWriteLock("ReadWriteC");
  readLockA = readWriteLockA.readLock();
  readLockB = readWriteLockB.readLock();
  readLockC = readWriteLockC.readLock();
  writeLockA = readWriteLockA.writeLock();
  writeLockB = readWriteLockB.writeLock();
  writeLockC = readWriteLockC.writeLock();

  CycleDetectingLockFactory.WithExplicitOrdering<MyOrder> factory2 =
      newInstanceWithExplicitOrdering(MyOrder.class, Policies.THROW);
  lock1 = factory2.newReentrantLock(MyOrder.FIRST);
  lock2 = factory2.newReentrantLock(MyOrder.SECOND);
  lock3 = factory2.newReentrantLock(MyOrder.THIRD);

  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory3 =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  lock01 = factory3.newReentrantLock(OtherOrder.FIRST);
  lock02 = factory3.newReentrantLock(OtherOrder.SECOND);
  lock03 = factory3.newReentrantLock(OtherOrder.THIRD);
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_reentrantAcquisition() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();
  Lock lockB = factory.newReentrantLock(OtherOrder.SECOND);

  lockA.lock();
  lockA.lock();
  lockB.lock();
  lockB.lock();
  lockA.unlock();
  lockA.unlock();
  lockB.unlock();
  lockB.unlock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories_policyExecution() {
  CycleDetectingLockFactory otherFactory = CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockD -> lockA
  lockD.lock();
  lockA.lock();
  lockA.unlock();
  lockD.unlock();

  // lockA -> lockD should warn but otherwise succeed because lockD was
  // created by a factory with the WARN policy.
  lockA.lock();
  lockD.lock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  CycleDetectingLockFactory factory = CycleDetectingLockFactory.newInstance(Policies.THROW);
  lockA = factory.newReentrantLock("LockA");
  lockB = factory.newReentrantLock("LockB");
  lockC = factory.newReentrantLock("LockC");
  ReentrantReadWriteLock readWriteLockA = factory.newReentrantReadWriteLock("ReadWriteA");
  ReentrantReadWriteLock readWriteLockB = factory.newReentrantReadWriteLock("ReadWriteB");
  ReentrantReadWriteLock readWriteLockC = factory.newReentrantReadWriteLock("ReadWriteC");
  readLockA = readWriteLockA.readLock();
  readLockB = readWriteLockB.readLock();
  readLockC = readWriteLockC.readLock();
  writeLockA = readWriteLockA.writeLock();
  writeLockB = readWriteLockB.writeLock();
  writeLockC = readWriteLockC.writeLock();

  CycleDetectingLockFactory.WithExplicitOrdering<MyOrder> factory2 =
      newInstanceWithExplicitOrdering(MyOrder.class, Policies.THROW);
  lock1 = factory2.newReentrantLock(MyOrder.FIRST);
  lock2 = factory2.newReentrantLock(MyOrder.SECOND);
  lock3 = factory2.newReentrantLock(MyOrder.THIRD);

  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory3 =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  lock01 = factory3.newReentrantLock(OtherOrder.FIRST);
  lock02 = factory3.newReentrantLock(OtherOrder.SECOND);
  lock03 = factory3.newReentrantLock(OtherOrder.THIRD);
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_reentrantAcquisition() {
  CycleDetectingLockFactory.WithExplicitOrdering<OtherOrder> factory =
      newInstanceWithExplicitOrdering(OtherOrder.class, Policies.THROW);
  Lock lockA = factory.newReentrantReadWriteLock(OtherOrder.FIRST).readLock();
  Lock lockB = factory.newReentrantLock(OtherOrder.SECOND);

  lockA.lock();
  lockA.lock();
  lockB.lock();
  lockB.lock();
  lockA.unlock();
  lockA.unlock();
  lockB.unlock();
  lockB.unlock();
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories_policyExecution() {
  CycleDetectingLockFactory otherFactory = CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockD -> lockA
  lockD.lock();
  lockA.lock();
  lockA.unlock();
  lockD.unlock();

  // lockA -> lockD should warn but otherwise succeed because lockD was
  // created by a factory with the WARN policy.
  lockA.lock();
  lockD.lock();
}