@Test
  public void registerAndGetKeyManager_works() throws Exception {
    ExecutorService threadPool = Executors.newFixedThreadPool(4);
    List<Future<?>> futures = new ArrayList<>();
    Registry.registerKeyManager(new TestKeyManager("KeyManagerStart"), false);
    futures.add(
        threadPool.submit(
            () -> {
              try {
                for (int i = 0; i < REPETITIONS; ++i) {
                  Registry.registerKeyManager(new TestKeyManager("KeyManager" + i), false);
                }
              } catch (GeneralSecurityException e) {
                throw new RuntimeException(e);
              }
            }));
    futures.add(
        threadPool.submit(
            () -> {
              try {
                for (int i = 0; i < REPETITIONS; ++i) {
                  assertNotNull(Registry.getUntypedKeyManager("KeyManagerStart"));
                }
              } catch (GeneralSecurityException e) {
                throw new RuntimeException(e);
              }
            }));

    threadPool.shutdown();
    // Wait forever: if the test times out we will notice independently.
    assertThat(threadPool.awaitTermination(1, DAYS)).isTrue();
    for (int i = 0; i < futures.size(); ++i) {
      futures.get(i).get(); // This will throw an exception if the thread threw an exception.
    }
  }
Thread safety tests for {@link Registry}.
java_src/src/test/java/com/google/crypto/tink/RegistryMultithreadTest.java