private static Callable<BigInteger> generateProbablePrimes() {
    return () -> {
      Random random = new Random();
      // To keep the CPU busy, we must prevent the Java and JIT compilers from optimizing this loop
      // out of existence. To do that, we save the the most recently generated prime, and return it
      // when the task is cancelled. Our assumption is that the compilers can't predict that the
      // return value is unused, and is therefore forced to calculate a new prime on each iteration.
      BigInteger prime = BigInteger.valueOf(0);
      while (!Thread.currentThread().isInterrupted()) {
        prime = BigInteger.probablePrime(1000, random);
      }
      return prime;
    };
  }
Cancels all current running threads.
The thread pool remains open, and this contention service can be reused.
geode-junit/src/main/java/org/apache/geode/test/concurrent/CPUContentionService.java