private void doLoadTest(Provider<? extends Thread> readerProvider,
                          Provider<? extends Thread> writerProvider,
                          final int numberOfThreads,
                          CountDownLatch writerStoppedSignal,
                          CountDownLatch readerStoppedSignal) throws Exception {
    List<Thread> writerThreads = new ArrayList<>();
    for (int i = 0; i < numberOfThreads; i++) {
      Thread readerThread = readerProvider.get();
      Thread writerThread = writerProvider.get();

      writerThreads.add(writerThread);

      readerThread.start();
      writerThread.start();
    }

    for (Thread writerThread : writerThreads) {
      writerThread.join();
      // Notify that one writer thread is stopped
      writerStoppedSignal.countDown();
    }

    // All writer threads are stopped. Reader threads should finish now.
    // Await for all reader threads to stop
    readerStoppedSignal.await();
  }
Launches reader and writer threads simultaneously to check for a deadlock.
The numbers of launched reader and writer threads are equal to
the {@code}numberOfThreads{@code}. This method expects that reader
and writer threads are using {@code}readerStoppedSignal{@code}
and {@code}writerStoppedSignal{@code} correctly.

Reader threads should be stopped after writer threads are finished.
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java