public void setup() {
    deadlockDetected = false;
    this.getExecutor().swapServerSession();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    person = (ConcurrentPerson) uow.registerObject(new ConcurrentPerson());
    person.name = "SomeoneSpecial";

    project = (ConcurrentLargeProject) uow.registerObject(new ConcurrentLargeProject());
    project.setName("ConcurrentRFJUOWLock Project");

    ConcurrentAddress address = (ConcurrentAddress) uow.registerObject(new ConcurrentAddress());
    address.setStreet("99 Bank St");
    project.setLocation(address);

    uow.commit();
    uow.release();
  }
  public void test() {
    Server server = this.getServerSession();
    UnitOfWork uow = server.acquireUnitOfWork();
    ConcurrentLargeProject clonedProject = (ConcurrentLargeProject) uow.registerObject(project);
    clonedProject.getLocation().setPostalCode("K1P 1A4");
    ConcurrentPerson clonedPerson = (ConcurrentPerson) uow.registerObject(person);
    clonedPerson.setHobby(clonedProject);
    uow.writeChanges();

    Thread thread1 = new Thread(new ProjectReader(server.acquireClientSession(), project.getId()));
    ConcurrentProject.RUNNING_TEST = ConcurrentProject.READ_WITH_UOW_LOCKS_TESTS;
    // start reading Project, and have the thread wait while building DTF mappings
    thread1.start();

    try {
      thread1.join(
          1000); // wait a token amount to be sure that thread1 isn't starved before getting
                 // deferred lock on Project.
    } catch (InterruptedException ex) {
    }

    // start uow commit, which will get locks on Person+Address, commit, then merge.
    // merge should get a deferred lock on Project.
    Thread thread2 = new Thread(new UOWCommit(uow));
    thread2.start();

    // while waiting, thread1 should wake and try to get a lock on Address.  It will deadlock if it
    // tries to get an active lock, since they will be held by the UOW which can't complete until
    // thread1
    // releases.
    try {
      thread1.join(20000);
      if (thread1.isAlive()) {
        try {
          thread1.interrupt();
          thread2.interrupt();
        } catch (Exception e) {
        }
        deadlockDetected = true;
      }
    } catch (InterruptedException ex) {
    }
  }
  public void reset() {
    ConcurrentProject.RUNNING_TEST = ConcurrentProject.NONE;
    UnitOfWork uow = getSession().acquireUnitOfWork();

    uow.deleteObject(person);
    uow.deleteObject(project);
    uow.deleteObject(project.getLocation());

    uow.commit();
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    this.getExecutor().resetSession();
  }